我有两个集合:
注释
{ 注释:[“狮子”,“斑马”,“眼镜蛇”], imagesId:1234}
{ 注释:[“狮子”,“斑马”,“眼镜蛇”,“狗”], imagesId:12345}图片
{_id:1234,…
如果我们不考虑保存 annotations 作为由...分隔的自由文本 , 这是一个坏主意,性能/响应时间不是您可能尝试的特定用例的问题 $查找 , 就像是:
annotations
,
Annotations.aggregate([ { $match: { annotations: { '$in': 'zebra' } } }, { $lookup: { from: "Images", localField: "imagesId", foreignField: "_id", as: "image" } } ]);