私信  •  关注

Anthony Winzlet

Anthony Winzlet 最近创建的主题
Anthony Winzlet 最近回复了
5 年前
回复了 Anthony Winzlet 创建的主题 » 当外部字段是对象数组时,MongoDB查找

您可以将下面的聚合与MongoDB一起使用 三点六 及以上

db.resources.aggregate([
  { "$match": { "type": "FUNC" } },
  { "$lookup": {
    "from": "initiatives",
    "let": { "id": "$_id" },
    "pipeline": [
      { "$match": { "$expr": { "$in": ["$$id", "$ressources.function"] } } },
      { "$unwind": "$ressources" },
      { "$match": { "$expr": { "$eq": ["$ressources.function", "$$id"] } } },
      { "$group": {
        "_id": "$ressources.function",
        "participation_sum": { "$sum": "$ressources.participating" }
      }}
    ],
    "as": "result"
  }}
])
5 年前
回复了 Anthony Winzlet 创建的主题 » MongoDB查询不相等

你必须使用 $expr 匹配同一文档中的两个字段

db.getCollection('user').find({
  "status" : "ACTIVE",
  "last_modified": { "$lt": new Date(), "$gte": new Date(new Date().setDate(new Date().getDate()-1)) }
  "$expr": { "$ne": ["$last_modified", "$time_created"] }
})