mongoDB 操作

来源:互联网 发布:php的laravel框架 编辑:程序博客网 时间:2024/06/05 22:58

索引

查看索引
b.collection.getIndexes()
添加索引
db.collection.createIndex()
eg. 在collection集合以ID正序,time倒序添加索引

db.collection.createIndex({"ID":1,"time":-1})

删除索引
db.collection.dropIndex()
eg.删除刚才创建的索引

db.collection.dropIndex({"ID":1,"time":-1})

mongodb索引文档
https://docs.mongodb.com/manual/indexes/

删除

db.collection.remove()

db.collection.remove({'title':'xxx'})

更改

eg.将title为123的记录的num 乘以10

db.collection.find({"title":"123"}).forEach(function(item){      db.collection.update({"_id":item._id},{"$set":{"num":item.num*10}},false,true)})