标签:exist foreach code each font multi find god cti
集合查询 4 db.TableName.find({"listData.listData1.field":2}); 5 非集合查询 6 db.TableName.find({"field":2}); 7 多条件查询 8 db.TableName.find({"field1":1,"field2":"test"}); 9 10 非集合新增 11 db.TableName.update({},{$set: {"new_field":1}}, {multi:true}) 12 db.TableName.update({"new_field":{$exists:false}},{$set:{"new_field":NumberInt("0")}},{multi:true}) 13 14 15 集合新增 16 db.Vac_Order.find({}).forEach(function(order){ 17 order.OrderDetail.forEach(function(detail){ 18 detail.MappingDetail.forEach(function(mapping){ 19 if(!mapping.newField){ 20 mapping.newField=0 //新增字段 21 } 22 }) 23 }) 24 db.Vac_Order.save(order) 25 }) 26 27 非集合删除 28 db.TableName.update({}, {$unset: {"new_field":1}},{multi:true}) 29 集合删除 30 db.Vac_Order.find({}).forEach(function(order){ 31 order.OrderDetail.forEach(function(detail){ 32 detail.MappingDetail.forEach(function(mapping){ 33 if(mapping.newField){ 34 delete mapping.newField//删除字段 35 } 36 }) 37 }) 38 db.Vac_Order.save(order) 39 }) 40 41 42 非集合修改 43 db.TableName.update({"field":"条件"},{$set:{"field":"新值"}},{multi:true}) 44 45 集合修改 46 db.Vac_Order.find({}).forEach(function(order){ 47 order.OrderDetail.forEach(function(detail){ 48 detail.MappingDetail.forEach(function(mapping){ 49 if(mapping.newField){ 50 mapping.newField=1//重新赋值 51 } 52 }) 53 }) 54 db.Vac_Order.save(order) 55 })
标签:exist foreach code each font multi find god cti
原文地址:https://www.cnblogs.com/wu-peng/p/9086642.html