查询某个字段存在的语句
db.getCollection('tableName').find({"RouteInfo":{"$exists":true}})
查询某个字段不存在的语句
db.getCollection('tableName').find({"RouteInfo":{"$exists":false}})
// 查某个数组属性的数组大小为1的
db.collection.find( { field: { $size: 1 } } );
// 查数组属性results匹配的
db.scores.find({ results: { $elemMatch: { $gte: 80, $lt: 85 } } })
// 分组count
db.getCollection('moments').aggregate( [{ "$group" : { "_id" : "$school.schoolId", "Count" : { "$sum" : 1 } } }])
// 使用其他collection的值更新关联的collection的字段值
db.getCollection('notices').find({}).forEach(function(notice) {
db.getCollection('noticereceivedetails').update(
{ "_notice": notice._id },
{ $set: { 'institutionId': NumberInt(notice.institutionId) }},
{ multi: true }
)
})