我正在尝试查询具有一对basename
和entries
的多个文档,而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
}
]
}
我知道basename
和crc
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
编辑:澄清了我的数据和查询
答案 0 :(得分:0)
rename 's/(.*_)([1-9]).pdf$/${1}0${2}.pdf/' first_1.pdf