一些简单的mongodb常用命令收集

1. $all 表示通过多个元素来匹配数组
2. $slice 指定偏移值,以及希望返回的元素数量
   db.user.find(aa,{"common":{"$slice":10}}) 


3. db.user.ensureIndex({"name":1}) 
   添加索引
4. db.user.drop() 删除集合
5. db.user.remove()  移除集合内数据,需要添加query


6. 使用db.user.find().hint({"username":1}) 使用hint来强制使用某个索引进行查询
7. db.user.ensureIndex({"username":1},{"unique":true}) 创建唯一索引
8. db.user.getIndexes()   查看给定集合中的索引信息


9.  db.user.aggregate({$group:{"_id":{"date":"$date","numa":"$numa"}}});
10. db.getCollectionNames(); 查询库表下的所有集合名称


11. show collections;  查看数据库下集合命令
    show dbs;          查看数据库命令

猜你喜欢

转载自blog.csdn.net/linwei_1029/article/details/50352782