MongoDB 安装 Basic Mongo Shell

Install MongoDB in win7:  http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/

(1)Download MongoDB zip , and unzip it.
(2)Config the mongoDB, config log and data dir.
      a. create a file "mongod.cfg" in the folder.
  b. add two items, more options please refer to the MongoDB manual:
        dbpath=D:\mongodb\data
        logpath=D:\mongodb\log
(3)Install the MongoDB as service, it's more convenient.
  Install Service: "D:\mongodb\bin\mongod.exe --config D:\mongodb\mongod.cfg --install"
  Start Service: "net start MongoDB"
  Stop Service: "net stop MongoDB"
  Remove Service: "D:\mongodb\bin\mongod.exe --remove"

Mongo Shell for MongoDB:  http://docs.mongodb.org/manual/tutorial/getting-started/

1. In cmd line, use "D:\mongodb\bin>start mongo.exe" to start the mongo shell.
2. "db": returns the name of the current database
3. "show dbs": display the list of databases
4. "use mydb": switch to db "mydb"
5. "help": or "xxx.help()" to show helps
------------------------------------------------------------------------------
6. "show collections": show the collections in this db
7. "db.things.insert(k)": insert docuemnt into the collection "things"

8. "db.things.find( { x : 4 } , { x:1, j : 2 } )":   后面的{x:1,j:2} 是投射,就是说找出来x=4的记录,并且展示出x和j的值。

原文地址:https://www.cnblogs.com/amosleaf/p/2966602.html