I have this document:
{
"_id" : ObjectId("5b774ebd88bff63a48a4019c"),
"modelo" : ObjectId("5b774ebc88bff63a48a40198"),
"tamano" : ObjectId("5b774ebc88bff63a48a40199"),
"color" : ObjectId("5b774ebc88bff63a48a40196"),
"terminado" : ObjectId("5b774ebc88bff63a48a40197"),
"laserAlmacen" : ObjectId("5b774ebd88bff63a48a4019b"),
"versionModelo" : ObjectId("5b774ebd88bff63a48a4019a"),
"__v" : 0
}
And I would like to search within objects, for example within% "modelo" : ObjectId("5b774ebc88bff63a48a40198"),
If I make a populate()
the modelo
returns me:
{
"_id" : ObjectId("5b774ebc88bff63a48a40198"),
"modelo" : "4125",
"__v" : 0
}
And I want to find all the documents that contain the same modelo.modelo
.
I've tried with:
ModelosCompletos.find({'modelo.modelo': regex }, (err, resp)=>{
//..Mas código...
})
But I do not get any results because it is not a nested document. I have been searching but I can not find how to solve this query.
I have thought of making two queries. The first one to search within the schema modelo
and return the _id
and then with this id search within ModelosCompletos
but I would like to know if you can do everything in a single request.