社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Anthony Winzlet  »  全部回复
回复总数  2
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"] }
})