mongo聚合

mongo聚合
{ $match: { avgTime: { $gt: 7 } } }
mongo $limmit use
{ $limit: 100 },
{ $limit: 10 }
取最小
mongo $skip use
{ $skip: 5 },
{ $skip: 2 }
取两个总和
mongo $match use
{ $match: { year: 2014 } },
{ $match: { status: "A" } }
{ $match: { $and: [ { "year" : 2014 }, { "status" : "A" } ] } }
相当于and
mongo $lookup and $unwind
{
  $lookup: {
    from: "otherCollection",
    as: "resultingArray",
    localField: "x",
    foreignField: "y"
  }
},
{ $unwind: "$resultingArray"}
$sort+ $skip+ $limit使用
{ $sort: { age : -1 } },
{ $skip: 10 },
{ $limit: 5 }
 单用途聚合操作
       db.distinct('cue_id')
    return 1
    { $match: { name: "Joe Schmoe" } },
{ $addFields: {
    maxTime: { $max: "$times" },
    minTime: { $min: "$times" }
} },
{ $match: { maxTime: { $lt: 20 }, minTime: { $gt: 5 } } },
{ $project: {
    _id: 1, name: 1, times: 1, maxTime: 1, minTime: 1,
    avgTime: { $avg: ["$maxTime", "$minTime"] }

示例:
  project = {'_id': 0, "title": 1, "link": "$pdf_link", "abstract": 1}
  pipeline = [{"$match": {'$or':[{'company_name': company_name},{'code':company_name}]}}, {"$sort": {"updated_at": -1}},
              {"$limit": 5}, {'$project': project}]
     db.aggregate(str(pipeline), collection, BASE)
     db.aggregate(str([{'$match:{'fileds':A}'},{'$group':{'_id':'$cue_id','totle':{'$sum':$amount}}}],collection, BASE))
      
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值