First, download address:
https://www.mongodb.com/download-center/community
Second, the installation error:
1, during installation error (similar to the FIG.):
Reason: No administrator rights
Resolution: The administrator runs cmd, find the file location, perform
1 msiexec /package node-v8.7.0-64.msi
Three, mongodb configuration
1, into the installation directory, the data in the folder, the new folder two log and DB, respectively, and store the log data as
2, add into the environment variable, add the path mongo where bin folder inside the path, such as D: \ MongoDB \ bin
3, in D: New mongo.config Files \ MongoDB \ bin directory, add the following (according to each person on the setting)
1 ## Database Contents ## 2 dbpath = D: \ MongoDB \ Data \ DB . 3 ## outputs the log file ## . 4 logpath = D: \ MongoDB \ Data \ log \ db.logAfter you add cmd run
1 mongod --config "E:\mongodb\mongo.config"4, added to the computer service, cmd window input
1 mongod --config "E:\mongodb\mongo.config" --install --serviceName "MongoDB"5、启动服务报错
在bin目录下有个mongod.cfg,打开,修成成下面:
1 # mongod.conf 2 3 # for documentation of all options, see: 4 # http://docs.mongodb.org/manual/reference/configuration-options/ 5 6 # Where and how to store data. 7 storage: 8 dbPath: D:\MongoDB\data\db 9 journal: 10 enabled: true 11 # engine: 12 # mmapv1: 13 # wiredTiger: 14 15 # where to write logging data. 16 systemLog: 17 destination: file 18 logAppend: true 19 path: D:\MongoDB\data\log\db.log 20 21 # network interfaces 22 net: 23 port: 27017 24 bindIp: 127.0.0.1 25 26 27 #processManagement: 28 29 #security: 30 31 #operationProfiling: 32 33 #replication: 34 35 #sharding: 36 37 ## Enterprise-Only Options: 38 39 #auditLog: 40 41 #snmp: 42 43 44
四、mangoDB常用语句
1 //显示所有数据库 2 show dbs 3 //选择数据库 4 use runoob 5 //删除数据库 6 db.dropDatabase() 7 //删除集合 8 db.collenction.drop() 9 //查找 10 db.staments.find() 11 //条件查找 12 db.staments.find({'title':'hello'}) 13 //插入单个文档 14 db.staments.insert({ 15 title:'hello', 16 url:'www.baidu.com', 17 like:100 18 }) 19 //插入多个文档 20 db.staments.insert([{ 21 title:'hello', 22 url:'www.baidu.com', 23 like:100 24 }, 25 { 26 title:'hello', 27 url:'www.baidu.com', 28 like:100 29 }, 30 { 31 title:'hello', 32 url:'www.baidu.com', 33 like:100 34 }]) 35 //更新文档 36 db.staments.update({'title':'MongoDB 教程'},{$set:{'title':'MongoDB'}}) 37 //删除文档 38db.satments.deleteMany ({}) // delete all 39 db.staments.deleteOne ({title: 'Hello'}) // delete a 40 db.staments.deleteMany ({title: 'Hello'}) // Delete a plurality of 41 is 42 is @ operator: $ lt smaller than, $ gt larger than, $ lte less, than or equal to $ GTE 43 is db.staments.find ({like: {$ gt: 50}}) 44 is // Sort 1 ascending, descending -1 45 db.staments.find () Sort (like: -1). 46 is 47