I have these schemas on my Mongo collection:
range = Schema
name: { type: String }
category = Schema
name: { type: String },
range: { type: Schema.ObjectId, ref: 'range' }
product = Schema
name: { type: String },
category: { type: Schema.ObjectId, ref: 'category' }
(I omitted all the other fields for brevity)
What I need is to execute a find() that returns all the products which are chidren of a specific range. As a filter, I use the range _id.
db.product.find( { "category.range._id": ObjectID("XXXXXX") });
This one does not work, and neither
db.product.find( { "category.range": ObjectID("XXXXXX") });
what's the correct way to query sub-subdocuments by _id?
Note: _ids are autogenerated by mongo
Thanks in advance!