这可以使用索引来解决,其中数组被选为术语。当以术语为目标的字段是数组时,会在数组中的per 项中生成一个单独的索引条目。所以假设现存的集合 parent 和 child 然后
db> CreateIndex({name: "cs", source: Collection("parent"), terms: [{field: ["data", "child"]}]})
{
ref: Index("cs"),
ts: 1569831659780000,
active: true,
serialized: true,
name: 'p',
source: Collection("parent"),
terms: [ { field: [ 'data', 'child' ] } ],
partitions: 1
}
会做生意。示例用法:
db> Create(Collection("child"), {})
{
ref: Ref(Collection("child"), "244918886014648845"),
ts: 1569831701200000
}
db> Create(Collection("child"), {})
{
ref: Ref(Collection("child"), "244918887478460941"),
ts: 1569831702590000
}
db> Create(Collection("parent"), {data:{child:[Ref(Collection("child"), "244918886014648845"), Ref(Collection("child"), "244918887478460941")]}})
{
ref: Ref(Collection("parent"), "244918956982272520"),
ts: 1569831768880000,
data: {
child: [
Ref(Collection("child"), "244918886014648845"),
Ref(Collection("child"), "244918887478460941")
]
}
}
db> Paginate(Match(Index("cs"), Ref(Collection("child"), "244918886014648845")))
{
data: [
Ref(Collection("parent"), "244918956982272520")
]
}
两个子引用都会匹配。