mongodb常用操作


查詢文檔列表

db.getCollection('documentinfo').find({"mustRead": true, "docStatus": "online", "$or": [{"docPermissionType": "public"}]}).count()

修改文檔字段名

//  單個修改
db.getCollection('exam').update({_id: "1f51310a-518f-4816-8518-302f4a8bd437"}, { $rename: { "employee_id": "employeeId" }})
//  批量修改
db.getCollection('exam').updateMany({}, { $rename: { "employee_id": "employeeId" }}) 
參加:https://docs.mongodb.com/manual/reference/operator/update/

更新,修改字段

db.getCollection('exam').updateOne({_id: "1f51310a-518f-4816-8518-302f4a8bd437"}, {$set: {"isPassed": false}} )

查詢文檔中某個字段是否存在

db.getCollection('userinfo').find({ "isPassed": { $exists: true } }).count()

刪除文檔中某個字段

//  刪除單個
db.getCollection('userinfo').delete({_id: "1f51310a-518f-4816-8518-302f4a8bd437"}, {$unset: {"duhuo": ''}} )
//  批量刪除
db.getCollection('userinfo').deleteMany({}, {$unset: {"duhuo": ''}} )

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM