假设我的数据库中有很多与此记录相似的记录
{
"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
不同的entries
现在,我有一个basename
和crc
个entries
的列表,我想要为其查找记录。像这样:
{
"basename": {
"$in": [
"2020bb",
"alpham2p"
]
},
"entries": {
"$in": [
[
{ "$elemMatch": { "crc": "4f5e19bd" } },
{ "$elemMatch": { "crc": "d6314bf0" } },
{ "$elemMatch": { "crc": "47fddfee" } }
],
[
{ "$elemMatch": { "crc": "c763e52a" } },
{ "$elemMatch": { "crc": "7a0b435c" } },
{ "$elemMatch": { "crc": "efc9ae2e" } }
]
]
}
}
通过此查询,我试图找到具有以下条件的项目
basename
值2020bb
的{{1}} entries
和crc
4f5e19bd, d6314bf0, 47fddfee
basename
和带有alpham2p
值entries
的{{1}} 我希望我的意图很明确。不幸的是,这只给了我0条结果。
答案 0 :(得分:-1)
db.collection.find({
basename: {
"$in": ["2020bb", "alpham2p"]
},
entries: {
$elemMatch: {
crc: {
$in: ["4f5e19bd", "d6314bf0", "47fddfee", "c763e52a", "7a0b435c", "efc9ae2e"]
}
}
}
})