MongoDB(mongodb-win32-x86_64-enterprise-windows-64-4.2.1-signed.msi)下载,启动和插入数据,查询
下载链接:https://pan.baidu.com/s/19lM5Q-_BaDbjaO1Pj0SbYg&shfl=sharepset
安装一路Next就行,安装完毕后,进入目录C:\Program Files\MongoDB\Server\4.2\bin>
启动控制台,输入
cd C:\Program Files\MongoDB\Server\4.2\bin>
C:\Program Files\MongoDB\Server\4.2\bin>mongod -dbpath "d:\mgdb\"
上面这条命令是让以d:\mgdb\为数据库文件所在目录启动db服务。
然后双击mongo.exe启动控制台。
使用以下命令插入数据并查询:
MongoDB Enterprise > use testdb switched to db testdb MongoDB Enterprise > db.stats() { "db" : "testdb", "collections" : 0, "views" : 0, "objects" : 0, "avgObjSize" : 0, "dataSize" : 0, "storageSize" : 0, "numExtents" : 0, "indexes" : 0, "indexSize" : 0, "scaleFactor" : 1, "fileSize" : 0, "fsUsedSize" : 0, "fsTotalSize" : 0, "ok" : 1 } MongoDB Enterprise > db.company.insert({name:"andy",age:20}) WriteResult({ "nInserted" : 1 }) MongoDB Enterprise > db.company.find() { "_id" : ObjectId("5daeb24ed0866807b20fe9ca"), "name" : "andy", "age" : 20 }
MongoDB Enterprise > db.company.insert( ... [ ... { name:"cindy",age:23}, ... { name:"douglas",age:34} ... ] ... ) BulkWriteResult({ "writeErrors" : [ ], "writeConcernErrors" : [ ], "nInserted" : 2, "nUpserted" : 0, "nMatched" : 0, "nModified" : 0, "nRemoved" : 0, "upserted" : [ ] }) MongoDB Enterprise > db.company.find() { "_id" : ObjectId("5daeb24ed0866807b20fe9ca"), "name" : "andy", "age" : 20 } { "_id" : ObjectId("5daeb3e7d0866807b20fe9cb"), "name" : "金兀术", "age" : 28, "sex" : "Male" } { "_id" : ObjectId("5daeb4bcd0866807b20fe9cc"), "name" : "cindy", "age" : 23 } { "_id" : ObjectId("5daeb4bcd0866807b20fe9cd"), "name" : "douglas", "age" : 34 } { "_id" : ObjectId("5daeb4fed0866807b20fe9ce"), "name" : "cindy", "age" : 23 } { "_id" : ObjectId("5daeb4fed0866807b20fe9cf"), "name" : "douglas", "age" : 34 } { "_id" : ObjectId("5daeb50ed0866807b20fe9d0"), "name" : "cindy", "age" : 23 } { "_id" : ObjectId("5daeb50ed0866807b20fe9d1"), "name" : "douglas", "age" : 34 } { "_id" : ObjectId("5daeb53fd0866807b20fe9d2"), "name" : "cindy", "age" : 23 } { "_id" : ObjectId("5daeb53fd0866807b20fe9d3"), "name" : "douglas", "age" : 34 } MongoDB Enterprise >
--END-- 2019年10月22日16:46:10