MongoDB 初始化

下载地址

https://www.mongodb.com/download-center/community

 

 下载完成后,一步步安装即可

初始化DB存放目录,找到安装MongoDB的目录下的bin目录,运行命令:

PS C:\mongodb\sERVER\4.2\bin>mongod --dbpath c:\data\db

然后你就会发现报错了

PS C:\Program Files\MongoDB\Server\4.2\bin> mongod --dbpath D:\MongoDB mongod : 无法将“mongod”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径
正确,然后再试一次。

PS C:\mongodb\sERVER\4.2\bin>.\mongod --dbpath c:\data\db

 总览数据库详情

PS C:\Program Files\MongoDB\Server\4.2\bin> .\mongo

查阅数据库

查看所有数据库

show dbs;

创建数据库

use databaseTest

创建表

> use filesDB
switched to db filesDB
> file = {
... name:'test.txt',
... path:'d://db/txt/'
... }
{ "name" : "test.txt", "path" : "d://db/txt/" }
> db.files.insert(file)
WriteResult({ "nInserted" : 1 })

查询表

db.files.find()

查询一条数据

db.files.findOne()

查询指定字段

1/ture为显示,0/false为隐藏

> db.files.find({},{name:1,_id:0,size:true})
{ "name" : "test.txt" }
{ "name" : "bus.doc", "size" : "10MB" }

 

posted @ 2019-08-22 15:02  咖啡漩涡  阅读(3814)  评论(0编辑  收藏  举报