I have two collections:
Annotations
{
annotations: ["lion", "zebra", "cobra"],
imagesId: 1234
}
{
annotations: ["lion", "zebra", "cobra", "dog"],
imagesId: 12345
}
Images
{_id:1234,
name: "africa"
}
{_id:12345,
name: "america"
}
I want to find all image names annotated with for example zebra
.
This is my pseudo approach:
let annotations = Annotations.find({annotations: {'$in': 'zebra'}});
getOnlyUniqueItems(annotations);
Images.find({_id: {'$in': annotations}});
It will work, problem is when annotations
contain for example 1M ids
, then query itself will be more then 1MB of text, it will probably kill my database.
Question: what is the best approach to this problem?
Thank you! :-)