MongoDBのクエリと集計パズルがあります。いくつかのサンプルレコードを拳:ドキュメントのサブセットの一意のフィールド値
# Document 1
{
items: [
{
type: "X",
id: 123
},
{
type: "Y",
id: 456
}
]
}
# Document 2
{
items: [
{
type: "A",
id: 789
},
{
type: "B",
id: 321
}
]
}
# Document 3
{
items: [
{
type: "P",
id: 987
},
{
type: "X",
id: 654
}
]
}
# Document 4
{
items: [
{
type: "Q",
id: 246
},
{
type: "X",
id: 654
}
]
}
は、私の目標は、id
がtype: X
要素に関連付けられているid
あるtype: X
を含む文書のためのすべての個別id
値を見つけることです。
例えば、上記では、私がする私の結果を希望するものである:
[ 123, 654 ]
これらはtype: X
に関連付けられているid
フィールドの一意の値です。