Why mongoose return empty results for an ObjectId that exists?
mongoose run this query which getting empty results.
const c = await Category.find({ subCategories: { '$in': [ { _id: mongoose.Types.ObjectId("5ccdc3dd4e88235af8923c62") } ] } });
console.log({ c });
mongoose response:
Mongoose: categories.find({ subCategories: { '$in': [ { _id: ObjectId("5ccdc3dd4e88235af8923c62") } ] } }, { projection: {} })
{ c: '[]' }
In my database there is results for this ObjectId...
Model definition:
const Category = mongoose.model(
'Category',
new mongoose.Schema({
name: { type: String },
subCategories: [
{
name: { type: String }
}
]
})
);