1.簡單查詢
db.getCollection('kycApplyPersonalRecord').find({'firstName':'123'})
代表在kycApplyPersonalRecord這個集合中查找firstName為123的文檔
通用示例:
db.getCollection('集合名').find({'字段名':'字段屬性'})
2.查詢某個字段不存在的文檔
db.getCollection('kycApplyPersonalRecord').find({'firstName':{$exists:false}})
代表在kycApplyPersonalRecord這個集合中查找firstName不存在的文檔
通用示例:
db.getCollection('集合名').find({'字段名':{$exists:false}})
3.查詢文檔的數(shù)量
db.getCollection('kycApplyPersonalRecord').find({'firstName':{$exists:false},'kycLevel':{$exists:true}}).count()
代表在kycApplyPersonalRecord這個集合中查找firstName不存在,kycLevel存在的文檔的數(shù)量
通用示例:
db.getCollection('集合名').find({'字段1':{$exists:false},'字段2':{$exists:true}}).count()
4.查詢大于睁冬,小于挎春,等于某個值的文檔
db.getCollection('kycApplyPersonalRecord').find({'kycLevel':{'$gt':1}})
代表在kycApplyPersonalRecord這個集合中查找kycLevel大于1的文檔
其中 ? ? ? ? $gt:大于;? ??$lt:小于豆拨;????$gte:大于或等于直奋;????$lte:小于或等于;
通用示例:
db.getCollection('集合名').find({'字段名':{'$gt':數(shù)值}})
5.查詢字段不為空的文檔
db.getCollection('kycApplyPersonalRecord').find({'uisRejectComment':{'$exists':true,'$ne':''}})
代表在kycApplyPersonalRecord這個集合中查找uisRejectComment這個字段存在且不為空字符串的文檔
通用示例:
db.getCollection("集合名").find({"字段名":{"$exists":true, "$ne":""}})
6.刪除指定字段
db.getCollection('kycApplyPersonalRecord').update({'uisRejectComment':{'$exists':true}},{$unset:{'appName':''}})
代表在kycApplyPersonalRecord這個集合中施禾,將'uisRejectComment'這個字段存在的文檔中的appName字段刪除
通用示例:
db.getCollection('集合名').update({'字段名':{$exists:true}}, {$unset:{'字段名':''}})
7.刪除滿足條件的文檔
db.getCollection('kycApplyPersonalRecord').remove({'kycLevel':1})
代表在kycApplyPersonalRecord這個集合中脚线,將kycLevel為1的文檔刪除
通用示例:
db.getCollection('集合名').remove({'字段名':'條件'})
8.按照指定字段排序顯示
db.getCollection('kycApplyPersonalRecord').find().sort({'pubTimestamp':1})
代表在kycApplyPersonalRecord這個集合中,將結(jié)果按照pubTimestamp升序顯示
通用示例弥搞;
db.getCollection('集合名').find().sort({"字段名":-1})?
其中 1 為升序排列邮绿,而 -1 是用于降序排列
9.只輸出顯示指定字段
db.getCollection('kycApplyPersonalRecord').find({},{'_id':1})
代表在kycApplyPersonalRecord這個集合中,只輸出顯示_id字段攀例,且按照_id字段升序顯示
通用示例:
db.getCollection('集合名').find({}, {'要顯示的字段':1})
最后船逮,執(zhí)行上述語句需要按鍵盤F5或者Ctrl+Enter(回車)