-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"strictPopulate" not working after upgrading from v5 to v6 #13863
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
IslandRhythms
added
the
help
This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
label
Sep 18, 2023
vkarpov15
added
needs repro script
Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
and removed
help
This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
labels
Sep 26, 2023
IslandRhythms
added
can't reproduce
Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.
and removed
needs repro script
Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
labels
Oct 18, 2023
const mongoose = require('mongoose');
const testSchema = new mongoose.Schema({
name: String,
location: String,
occupation: String,
});
const ASchema = new mongoose.Schema({
name: String,
age: Number,
weight: Number,
dModel: {
type: mongoose.Schema.Types.ObjectId,
ref: 'DModel'
},
fModel: {
type: mongoose.Schema.Types.ObjectId,
ref: 'FModel'
}
});
const XSchema = new mongoose.Schema({
name: String,
car: String,
make: String,
model: String,
aModel: {
type: mongoose.Schema.Types.ObjectId,
ref: 'AModel'
},
testModel: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Test'
},
cModel: {
type: mongoose.Schema.Types.ObjectId,
ref: 'CModel'
}
});
const CSchema = new mongoose.Schema({
name: String,
hobbies: String
})
const DSchema = new mongoose.Schema({
name: String,
});
const FSchema = new mongoose.Schema({
name: String,
});
const GSchema = new mongoose.Schema({
name: String
});
const Test = mongoose.model('Test', testSchema);
const AModel = mongoose.model('AModel', ASchema);
const XModel = mongoose.model('XModel', XSchema);
const CModel = mongoose.model('CModel', CSchema);
const DModel = mongoose.model('DModel', DSchema);
const FModel = mongoose.model('FModel', FSchema);
const GModel = mongoose.model('GModel', GSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
const gDoc = await GModel.create({
name: 'G-Man'
});
const dDoc = await DModel.create({
name: 'Dirty Dan',
});
const fDoc = await FModel.create({
name: 'Filthy Frank',
});
const testDoc = await Test.create({
name: 'Test Testserson',
location: 'Florida',
occupation: 'Tester'
});
const aDoc = await AModel.create({
name: 'A-men',
age: 4,
weight: 404,
dModel: dDoc._id,
fModel: fDoc._id
});
const cDoc = await CModel.create({
name: 'C-ya',
hobbies: 'Leaving'
});
await XModel.create({
name: 'XCOM',
aModel: aDoc._id,
cModel: cDoc._id,
testModel: testDoc._id
});
const res = await XModel.find().populate({
path: 'aModel testModel cModel',
populate: {
path: 'dModel fModel',
populate: 'gModel',
strictPopulate: false
}
});
console.log('what is res', res[0]);
console.log('==============================');
console.log('what is amodel in the doc', res[0].aModel)
console.log('done');
}
run(); |
IslandRhythms
added
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
can't reproduce
Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.
labels
Oct 18, 2023
I did some debugging and it looks like this is expected behavior. You need to apply .populate({
path: 'a b c', // direct keys available in schema for X
populate: {
path: 'd c', // direct keys available in schema for A (not X)
populate: { path: 'e', strictPopulate: false } // indirect keys outside of schema for X
},
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Mongoose version
6.12.0
Node.js version
16.20.0
MongoDB server version
6.0.10
Typescript version (if applicable)
4.7.4
Description
Hi,
We are trying to upgrade our atlas cluster from v5 to v6, for which, we tried upgrading mongoose to prevent any server-level compatibility issues however we keep getting errors around
strictPopulate
.Seemingly the type-declaration for global override has been already added (ref: #11006) which did not work.
This is inside NestJS v7 (
@nestjs/mongoose: ^7.2.4
)Steps to Reproduce
Example Code Throwing Error:
Expected Behavior
Should not throw any error or allow server to run while gracefully putting a warning
The text was updated successfully, but these errors were encountered: