On first reading the question this appeared to be a query casting issue, but if you’ve already cast objectId to an ObjectId then this may not be the case.
Can you enable logging and verify that (a) the query that’s being sent to the server is correct and (b) the correct cluster/database/collection is being targeted? This should make it a lot easier to determine what’s going wrong.
I’ve enabled logging as you requested. I added an additional query to fetch an entry from ID to ensure that the server, cluster, and DB are correct. Log results:
It seems like even though I’m making an explicit cast of the propertyId to an ObjectId, it’s still being registered as a string. Below is the exact code I used to get the above output:
mongoose.set('debug', true);
const imageId = '65ad42687b060d6038177e45';
const image = await this.imageModel.findById(imageId);
console.log('[DEBUG] Image label:', image.label);
const ObjectId = mongoose.Types.ObjectId; // import is out of view, but same as before
const results = await this.imageModel.find({ propertyId: new ObjectId(propertyId) });
console.log('[DEBUG] Results:', results);
return results;