First, prepare
Download mongodb
https://www.mongodb.com/download-center/community
The example is: mongodb-win32-x86_64-2008plus-ssl-3.2.4-signed.msi
Second, the installation
Installation process of the same process that ordinary software. Where the main attention is to choose the right installation location, the installation path, it is best not to appear Chinese or spaces.
Installation Process Reference Links: https://www.runoob.com/mongodb/mongodb-window-install.html
Third, the configuration
1, configure the environment variables
2, will be added to the system services mongodb
Open a command line window administrator mode
mkdir c:\data\db mkdir c:\data\log
Two directories created above the out, the future is a place to store data and log files. You can customize the location.
Create a profile, create mongod.cfg, file content in mongodb installation directory
systemLog: destination: file path: c:\data\log\mongod.log storage: dbPath: c:\data\db
By executing mongod.exe, use the --install option to install the service, using the --config option to specify the configuration file you created earlier. Such as:
D:\Program_Files\MongoDB\Server\3.2\bin>mongod.exe --config "D:\Program_Files\MongoDB\mongod.cfg" --install
Check whether the service is added successfully, and start mongodb
3. Start and test
启动可以在服务窗口中找到mongodb启动,或者通过“net start mongodb”命令启动
测试
C:\Users\Administrator>mongo
MongoDB shell version: 3.2.4 connecting to: test Welcome to the MongoDB shell.
For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions?
Try the support group http://groups.google.com/group/mongodb-user
> 2+2
4
> db
test
> db.runoob.insert({x:10})
WriteResult({ "nInserted" : 1 })
> db.runoob.find()
{ "_id" : ObjectId("5d57c3879bd75e032f9a3d48"), "x" : 10 }
>use test
> db.test.insert({"stuId":11,"stuName":"jones","stuClass":3})
WriteResult({ "nInserted" : 1 })
> db.test.find()
{ "_id" : ObjectId("5d57c5099bd75e032f9a3d49"), "stuId" : 10, "stuName" : "jack", "stuClass" : 2 }
{ "_id" : ObjectId("5d57e2d664278756e3757aa5"), "stuId" : 11, "stuName" : "jones", "stuClass" : 3 }
>
如果在使用的时候出现如下的错误信息,请参照博客中的方法解决:
2019-08-17T17:00:31.957+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:10061 由于目标计算机积极拒绝,无法连接。 2019-08-17T17:00:31.958+0800 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed : connect@src/mongo/shell/mongo.js:224:14 @(connect):1:6
这是由于mongodb没有启动所导致的,解决方法参考博客https://www.cnblogs.com/greenteaone/p/3745734.html
四、通过其他工具管理mongodb
在cmd中操作mongodb不是太方便,推荐使用工具,mongodb manager或Studio 3T
使用mongodb manager
也可以使用“Studio 3T”工具