十四、mongoDB之find操作

版权声明:本文为博主原创文章,未经博主允许欢迎转载,请注明原文链接。一起交流,共同进步。 https://blog.csdn.net/newbie_907486852/article/details/82722276

                   mongoDB之find操作

运算符 含义
find 查询文档
findAndModify 查询和修改同时
findOne 查询一个,多个结果返回第一个
findoneAndDelete 查询并删除符合条件的
findOneAndReplace 查询并替换符合条件的
findoneAndUpdate 插入一个或者多个



db.products.find( { qty: { $gt: 25 } } )


db.people.findAndModify({
    query: { name: "Tom", state: "active", rating: { $gt: 10 } },
    sort: { rating: 1 },
    update: { $inc: { score: 1 } }
})


db.bios.findOne(
   { contribs: 'OOP' },
   { _id: 0, 'name.first': 0, birth: 0 }
)


db.scores.findOneAndDelete(
   { "name" : "M. Tagnum" }
)


//查询并替换符合条件的
db.mycollection.findOneAndReplace(
   { "score" : { $lt : 20000 } },
   { "team" : "Observant Badgers", "score" : 20000 },
   { sort: { "score" : 1 } }
)

//查询并更新
db.scores.findOneAndUpdate(
   { "name" : "R. Stiles" },
   { $inc: { "points" : 5 } }
)

猜你喜欢

转载自blog.csdn.net/newbie_907486852/article/details/82722276