Closed ammarlakho closed 1 year ago
const mongoose = require('mongoose');
const testSchema = new mongoose.Schema({
name: String,
businesses: []
});
const Test = mongoose.model('Test', testSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
await Test.create({
name: 'Test',
businesses: [{field: 'subField'}]
});
const res = await Test.findOne({ "businesses.field": "subField"})
console.log('res', res)
const empty = await Test.findOne({ "businesses.field": "asdf"});
console.log('empty', empty);
}
run();
This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days
This issue was closed because it has been inactive for 19 days since being marked as stale.
Prerequisites
Mongoose version
6.4.2
Node.js version
16.17.0
MongoDB server version
6.0.1
Description
I am facing a discrepancy in query results between mongoose and the mongsh in MongoDB Compass. The problem seems to be in the mongoose result. This is only happening when my query filter includes an embedded array.
Steps to Reproduce
These queries are being run on a MongoDB database with a collection called users with only 1 document. This is the user document:
Expected Behavior
For the 2nd query
findOne({"businesses.firestore_id": "This is an invalid id"})
, the result should have been null, like the result for from the mongo shell.