First, you have to be able to enter the console, not to solve their own.
Basic operation:
Show Users: Show user
Show DBS: Display Database list
Use <db name> switch/CREATE Database
Show Collections: Displays a collection in the current database (similar to a table in a relational database)
Db.help (): Show database Operations Command with a lot of commands
Db.<collections>.help ()
Db<collections>.find ()
Db.<collections>.find ({a:1})
Common statements:
Import and export files to the database
mongoexport-d test-c Students-o Students.dat
mongoexport-d test-c students--csv-f classid,name,age-o Students_csv.dat
Create a database
Use <db name> #创建集合时自动创建use的数据库
Db.clonedatabase ("127.0.0.1") 3 clone the database from the specified machine to the current use database
Db.getname () #显示当前数据库
Db.stats () Displays the current DB status
Db.version ()
Db.getmongo () #当前db链接机器地址
Deleting a database
Db.dropdatabase ()
Modify Database
Db.repairdatabase () #修复数据库
User Management
Db.adduser ("name") #
Db.adduser ("UserName", "pwd123", True) #添加用户, set password, read-only
Db.auth ("UserName", "123123") #数据库认证, Safe mode
Show Users #显示当前所有用户
Db.removeuser ("UserName") #删除所有用户
Db.getpreverror () #查询错误信息
Db.reseterror () #清空错误日志
Create a Collection
Db.createcollection ("Collname", {size:20, Capped:5, max:100});
Delete Collection
Modify a Collection
Query collection data/collection name
Db.getcollection ("account") #查询指定集合
Db.getcollectionnames () #查询当前数据库的所有集合
Db.printcollectionstats () #显示当前db索引状态
Db<collections>.find () #查询指定集合的数据
MONGO Common syntax