Closed DerickBastos closed 1 week ago
Tested on 6.11.6, 7.4.0, and 8.5.2 and am unable to reproduce.
const mongoose = require('mongoose');
const channelSchema = new mongoose.Schema({
name: String
});
const testSchema = new mongoose.Schema({
channels: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Channel'}]
});
const Test = mongoose.model('Test', testSchema);
const Channel = mongoose.model('Channel', channelSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
const channelOne = await Channel.create({
name: 'TestOne'
});
const channelTwo = await Channel.create({ name: 'TestTwo' });
await Test.create({
channels: [channelOne._id, channelTwo._id]
});
const res = await Test.find({
$and: [{
$or: [
{ channels: { $exists: false } },
{ channels: { $size: 0 } },
{ channels: { $elemMatch: { $in: [channelOne._id] } } }
]
}]
}).getFilter();
console.log('what is res', res, res.$and[0].$or, res.$and[0].$or[2].channels.$elemMatch);
console.log('done');
process.exit(0)
}
run();
What does your schema look like @DerickBastos ?
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 and has been marked as stale.
Prerequisites
Mongoose version
6.11.6 to 7.4.0
Node.js version
16.17.0
MongoDB server version
7.0.12
Typescript version (if applicable)
No response
Description
After upgrading to Mongoose version 7.4.0, I noticed that the query is no longer returning the same results as it did in version 6.11.6. I found that the query was incomplete, with the $in clause being removed
Steps to Reproduce
version mongoose 6.11.6:
version mongoose 7.4.0:
Expected Behavior
The expected behavior is that Mongoose does not remove parts of my query, as this is affecting the expected results.