Mongoose: Querying on Object ID type

Hey Alex, thanks for the quick reply.

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:

Mongoose: images.findOne({ _id: ObjectId("65ad42687b060d6038177e45") }, {})
[DEBUG] Image label: EXTERIOR
Mongoose: images.find({ propertyId: '6578f033adc722b67624a271' }, {})
[DEBUG] 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;