2. #增加或修改用户密码
3. #查看用户列表
' \4 b- @7 }7 i! L# l0 v* i
4. #用户认证
( V) c' L# i3 V; l' |3 v3 e3 c* b
5. #删除用户
6. #查看所有用户
7. #查看所有数据库
8. #查看所有的collection
9. #查看各collection的状态
- db.printCollectionStats()
复制代码 1 [% r7 T: N; }9 ^: M
10. #查看主从复制状态
- db.printReplicationInfo()
复制代码
! E! o. c8 Y8 l 11. #修复数据库
12. #设置记录profiling,0=off 1=slow 2=all
13. #查看profiling
4 \( I5 m; Y" O' l1 u$ J' U
14. #拷贝数据库
- db.copyDatabase('mail_addr','mail_addr_tmp')
复制代码
, f1 \, C, x: a N 15. #删除collection
16. #删除当前的数据库
2. 增删改
1. #存储嵌套的对象
- db.foo.save({'name':'ysz','address':{'city':'beijing','post':100096},'phone':[138,139]})
复制代码 - ?8 e! w/ N, P1 b
2. #存储数组对象
- db.user_addr.save({'Uid':'yushunzhi@sohu.com','Al':['test-1@sohu.com','test-2@sohu.com']})
复制代码
+ t! K3 f6 y$ |) ^ 3. #根据query条件修改,如果不存在则插入,允许修改多条记录
- db.foo.update({'yy':5},{'$set':{'xx':2}},upsert=true,multi=true)
复制代码 ) P9 E, |1 {6 a6 q3 E, s8 N; }% [
4. #删除yy=5的记录
6 [' {9 l. f7 ?' B# w" D& ~
5. #删除所有的记录
3. 索引
1. #增加索引:1(ascending),-1(descending)
2. db.foo.ensureIndex({firstname: 1, lastname: 1}, {unique: true});
3. #索引子对象
4. db.user_addr.ensureIndex({'Al.Em': 1})
5. #查看索引信息
6. db.foo.getIndexes()
7. db.foo.getIndexKeys()
8. #根据索引名删除索引
9. db.user_addr.dropIndex('Al.Em_1')
4. 查询
1. #查找所有
2. db.foo.find()
3. #查找一条记录
4. db.foo.findOne()
5. #根据条件检索10条记录
6. db.foo.find({'msg':'Hello 1'}).limit(10)
7. #sort排序
8. db.deliver_status.find({'From':'ixigua@sina.com'}).sort({'Dt',-1})
9. db.deliver_status.find().sort({'Ct':-1}).limit(1)
10. #count操作
11. db.user_addr.count()
12. #distinct操作,查询指定列,去重复
13. db.foo.distinct('msg')
14. #”>=”操作
15. db.foo.find({"timestamp": {"$gte" : 2}})
16. #子对象的查找
17. db.foo.find({'address.city':'beijing'})
5. 管理
1. #查看collection数据的大小
2. db.deliver_status.dataSize()
3. #查看colleciont状态
4. db.deliver_status.stats()
5. #查询所有索引的大小
6. db.deliver_status.totalIndexSize()
# P, `9 [$ \: |" q- b
6. 高级查询
条件操作符
9 `* E* k9 N" K0 f! _, j5 @+ P