查詢文檔列表
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": ''}} )