I am using nodejs, mongoose (so mongodb as a database) and javascript.
I have a collection named A which some examples are the following:
{
"item": "Kitchen",
"location": "New York",
"ids" : [ ObjectId("5f6dce24021e15a1121a649a"), ObjectId("5f6dce24021e15a1121a649b"), ObjectId("5f6dce24021e15a112a649c")]
}
{
"item": "Bathroom",
"location": "New York",
"ids" : [ObjectId("5f6dce24021e15a112a649c")]
}
{
"item": "Living Room",
"location": "New York",
"ids" : [ ObjectId("5f6dce24021e15a1121a649a"), ObjectId("5f6dce24021e15a1121a649b")]
}
The ids are the references to another collection which I will name B. An example would in the collection B is the following:
{
"_id" : ObjectId("5f6dce24021e15a1121a649a"),
"name" : "George",
"Age": 12,
"Nationality": "English"
}
I would like to be able to find all items in collection A which have ObjectId("5f6dce24021e15a1121a649a") in the ids array.
Excepted Result: ["Kitchen", "Living Room"]
Does anyone have an idea how I could processed?