MongoError:无法在$ in下嵌套$

时间:2019-01-17 21:49:11

标签: mongodb mongodb-query

我正在尝试查询具有一对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 s,并且我试图找到许多包含适当对的物品。为此,我正在使用$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

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

1 个答案:

答案 0 :(得分:0)

rename 's/(.*_)([1-9]).pdf$/${1}0${2}.pdf/' first_1.pdf