mongodb - 蒙哥错误: cannot nest $ under $in

我正在尝试查询具有一对 basenameentries 的多个文档,而 entries 是一个包含名为 CRC

2 item2 的示例:

{
  "basename": "2020bb",
  "entries": [
    {
      "name": "030-c1.bin",
      "extension": "bin",
      "basename": "030-c1",
      "crc": "4f5e19bd",
      "size": 1048576
    },
    {
      "name": "030-c2.bin",
      "extension": "bin",
      "basename": "030-c2",
      "crc": "d6314bf0",
      "size": 1048576
    },
    {
      "name": "030-c3.bin",
      "extension": "bin",
      "basename": "030-c3",
      "crc": "47fddfee",
      "size": 1048576
    }
  ]
},
{
  "basename": "mutnat",
  "entries": [
    {
      "name": "sp-s2.sp1",
      "extension": "sp1",
      "basename": "sp-s2",
      "crc": "9036d879",
      "size": 1048576
    },
    {
      "name": "sp-s3.sp1",
      "extension": "sp1",
      "basename": "sp-s3",
      "crc": "c7f2fa45",
      "size": 1048576
    },
    {
      "name": "sp-4.sp1",
      "extension": "sp1",
      "basename": "sp-s4",
      "crc": "e72943de",
      "size": 1048576
    }
  ]
}

我知道 basenamecrc,我正试图找到许多包含正确对的项目。为此,我使用了 $in$all$elemMatch

{
  "basename": {
    "$in": [
      "2020bb",
      "mutnat"
    ]
  },
  "entries": {
    "$in": [
      {
        "$all": [
          { "$elemMatch": { "crc": "4f5e19bd" } },
          { "$elemMatch": { "crc": "d6314bf0" } },
          { "$elemMatch": { "crc": "47fddfee" } }
        ]
      },
      {
        "$all": [
          { "$elemMatch": { "crc": "9036d879" } },
          { "$elemMatch": { "crc": "c7f2fa45" } },
          { "$elemMatch": { "crc": "e72943de" } }
        ]
      }
    ]
  }
}

请注意,只是为了这个示例的简洁,我在 $in 中只有一项。实际上,这些数组中有多个项目。

但是使用这个查询我得到了这个错误:

MongoError: cannot nest $ under $in

编辑:澄清了我的数据和我的查询

最佳答案

db.xxx.find({
  "basename": "2020bb",
  "entries": {
     $elemMatch: {
       "crc": { $in: ["4f5e19bd", "d6314bf0", "47fddfee" ] }
     }
   }
})

https://stackoverflow.com/questions/54244796/

相关文章:

vb.net - 按列 ("TagIndex = 5"搜索 dgv 列)

python - 如何读取 main_file.exe 中的 data.txt 而不将它们保存在 p

swift - 如何修复此 'required condition is false: format

javascript - Webpack Import Code Splitting 渲染

javascript - typescript 在不同类型的数组中查找

r - 如何从 Shiny 中的 plotly 事件中获取方面数据

python-3.x - odoo 从代码向用户发送消息(通知)

amazon-web-services - AWS Glue - 从现有笔记本服务器访问新的开发端点

bash - 如何以编程方式从 docker-compose.yml 中删除服务?

ios - 为 App Store 准备不同分辨率的 App Preview 视频