MONGO additions and deletions to search
Show DBS shows all DB
To which db the use Fengdb is converted, without which a new db is created automatically
DB Displays the current operation's DB
Db.fengDb.insert ({"Name": "Fengnovo"}) adds a record to the FENGDB
Db.dropdatabase () Delete current db (FENGDB)
Use Fengdb to move objects to db
Show collections shows that the above DB is fengdb all the collections under this database
Db.printcollectionstats () #查看各collection的状态
Db.user1.drop () Delete the User1 collection under the Fengdb database
Show Users view all users
Db.adduser (' admin ', ' pwd ') #增加或修改用户密码
Db.user1.save ({' name ': ' Fengnovo ', ' age ': +, ' favor ': [' singing ', ' playing ']}) #存储嵌套的对象
Db.user1.save ({' name ': ' Fengnovo ', ' age ': +}) #存储数组对象
Db.user1.update ({' name ': ' Fengnovo '},{' $set ': {' age ': 27}},upsert=true,multi=true)
#根据query条件修改, insert if not present, allow multiple records to be modified
Db.user1.remove ({' Age ': ') #删除age =24 Records
db.user1.remove () #删除所有的记录
Db.user1.find () #查找所有
Db.user1.findOne ({' name ': ' Fengnovo '}) #查找一条记录
Db.user1.find ({' name ': ' Fengnovo '}). Limit ( #根据条件检索10条记录)
Db.user1.find ({' name ': ' Fengnovo '}). Sort ({' Age ': 1}) by age positive order
Db.user1.find ({' name ': ' Fengnovo '}). Sort ({' Age ':-1}) by age
Reverse
Db.user1.find (). Sort ({' age ':-1}). Limit (1) #sort排序
Db.user1.count () #count操作, number of User1 collections
Db.user1.distinct (' age ') #distinct操作, take the value of age only
Db.user1.find ({"Age": {' $gte ':}}) #>= operation
Db.user1.find ({"Age": {' $lte ':}}) #<= operation
Db.user1.find ({' address.city ': ' Beijing '}) #子对象的查找
The following excerpt from http://hackpro.iteye.com/blog/1278105
Db.help ();
1. Super User-Related:
#增加或修改用户密码
Db.adduser (' admin ', ' pwd ')
#查看用户列表
Db.system.users.find ()
#用户认证
Db.auth (' admin ', ' pwd ')
#删除用户
Db.removeuser (' MongoDB ')
#查看所有用户
Show Users
#查看所有数据库
Show DBS
#查看所有的collection
Show collections
#查看各collection的状态
Db.printcollectionstats ()
#查看主从复制状态
Db.printreplicationinfo ()
#修复数据库
Db.repairdatabase ()
#设置记录profiling, 0=off 1=slow 2=all
Db.setprofilinglevel (1)
#查看profiling
Show profile
#拷贝数据库
Db.copydatabase (' mail_addr ', ' mail_addr_tmp ')
#删除collection
Db.mail_addr.drop ()
#删除当前的数据库
Db.dropdatabase ()
2. Client Connection
/usr/local/mongodb/bin/mongo user_addr-u user-p ' pwd '
3. Index
Added index: 1 (ascending), -1 (Descending)
Db.things.ensureIndex ({firstname:1, lastname:1}, {unique:true});
#索引子对象
Db.user_addr.ensureIndex ({' Al.em ': 1})
#查看索引信息
Db.deliver_status.getIndexes ()
Db.deliver_status.getIndexKeys ()
#根据索引名删除索引
Db.user_addr.dropIndex (' al.em_1 ')
4. Management
#查看collection数据的大小
Db.deliver_status.dataSize ()
#查看colleciont状态
Db.deliver_status.stats ()
#查询所有索引的大小
Db.deliver_status.totalIndexSize ()
MongoDB Base Statement