I have a saved a collection in my database and I want to filter it using companyId and cameras using ObjectId specific.
In the follow is the collection that a want to get.
{
"_id": ObjectID("5c3b584fa7e1b10155e6325f"),
"companyId": "5c3b5468a7e1b10155e9995b",
"name": "Place Test",
"cameras": {
"0": ObjectID("5c9149e3f054d00028cc9604"),
"1": ObjectID("5c9149e3f054d00028cc9605")
}
}
I'm trying to filter like:
const placeCollection = req.app.locals.db.collection('places')
const place = placeCollection.findOne({
companyId: req.body.companyId,
cameras: { $elemMatch: { $eq: new ObjectId(req.body.cameraId) } }
})
but not working with cameras filter, only with companyId.