1.查询
/** or **/
db.getCollection('collectionName').find({$or: [{"fieldName1": 10424}, {"fieldName2": 676}]});
/** in、not in **/
db.getCollection('collectionName').find({"fieldName": {$in: [10424, 24457]}});
db.getCollection('collectionName').find({"fieldName": {$nin: [24456, 24457]}});
/** !=、<、>、<=、>= **/
db.getCollection('collectionName').find({"fieldName": {$ne: null}});
db.getCollection('collectionName').find({"fieldName": {$lt: 24456}});
db.getCollection('collectionName').find({"fieldName": {$gt: 24456}});
db.getCollection('collectionName').find({"fieldName": {$lte: 24456}});
db.getCollection('collectionName').find({"fieldName": {$gle: 24456}});
/** like **/
db.getCollection('collectionName').find({"fieldName": /te/});
db.getCollection('collectionName').find({"fieldName": /^te/});
db.getCollection('collectionName').find({"fieldName": /te$/});
/** count、limit、skip、sort、distinct**/
db.getCollection('collectionName').count();
db.getCollection('collectionName').find().limit(10).skip(5);
db.getCollection('collectionName').find().sort({"fieldName": -1});
db.getCollection('collectionName').distinct("fieldName1", {"fieldName2":223});
/** list操作 **/
db.getCollection('collectionName').find({"fieldName1": {$elemMatch: {"fieldName2": 6266}}});
db.getCollection('collectionName').find({"fieldName1.0.fieldName2": 6266});
db.getCollection('collectionName').find({"fieldName": {$size: 8}});
/** 投影 **/
db.getCollection('collectionName').find({"fieldName": 223}, {"fieldName1": 1});
db.getCollection('collectionName').find({"fieldName": 223}, {"fieldName2": 0});
/** group **/
db.getCollection('collectionName').group({
key: {"fieldName1": 1},
cond: {"fieldName2": {$gte: 233}},
reduce: function(curr, result) {
result.total += 1;
},
initial:{total: 0}
});
2.更新
/** update **/
db.getCollection('collectionName').update({'fieldName': 88888}, {$set: {'fieldName': 8888}}, false, true);
db.getCollection('collectionName').update({'fieldName': 88888}, {$set: {'fieldName': 8888}}, {multi: true});
db.getCollection('collectionName').update({'fieldName': 88888}, {$unset: {'fieldName': 8888}}, false, true);
3.删除
/** delete、drop **/
db.getCollection('collectionName').remove({"fieldName": 88888});
db.getCollection('collectionName').drop();
4.索引
db.getCollection('collectionName').createIndex({"fieldName": 1}, {background: true});
db.getCollection('collectionName').dropIndex("fieldName");
db.getCollection('collectionName').getIndexes();
db.getCollection('collectionName').totalIndexSize();
db.getCollection('collectionName').dropIndexes();