zhaoyu@home:~$

mongo

查询例子

db.getCollection('xkgoods_bcle_m_shop').find({"_id" : ObjectId("5beb95050334551f70333121")})

db.getCollection('xk_api_access_log_20190103').find({"app":"sys_api","service":"goodsCatalogList"}).limit(10).sort({"createdAt":-1})

//分组
db.xkgoods_j_goods_jsequence.aggregate([{$group: {_id:'$goods._id', personCount: {$sum: 1}}}])

db.xkgoods_j_goods_jsequence.group({
    key:{'goods._id':true},
    initial: {count: 0},
    reduce: function(obj,prev){ //obj表示当前文档,prev表示累加器文档
        prev.count++;
    },
    finalize: function(out){ out.scaledCount = out.count * 10}//在结果文档中新增一个键,out表示最终的输出行
})

时间区间查询

//查询date 大于等于2020-08-13 15:00:11,小于当前时间的数据。
db.getCollection('turnover_statistics').find({date:{$gte:ISODate("2020-08-13 15:00:11"),$lte:new Date()}})

robo 3t查询超过30条。

DBQuery.shellBatchSize = 500;

当前窗口最大查询数量修改到500(只有当前窗口生效)

指定字段查询

如下指定查询字段为address,account。_id字段会默认显示。需要取消字段,设置为-1。

db.getCollection('ANT_address_book').find({},{address:1,account:1}).sort({account:1})