-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
[DOCS] Add more documentation about virtual populate option match
#11321
Comments
According to the code, the foreignField allow a function : https://github.com/Automattic/mongoose/blob/master/lib/helpers/populate/getModelsMapForPopulate.js#L391 |
Yes, |
We have a section in the populate docs about |
is the same true for |
Unfortunate inconsistency between |
im my last question (for reference, i mean this comment) i asked about the difference between because of the following code: // NodeJS: 17.3.0
// MongoDB: 4.2-bionic (Docker)
import * as mongoose from 'mongoose'; // [email protected]
const nestedSchema = new mongoose.Schema({
parent: mongoose.Schema.Types.ObjectId,
});
const parentSchema = new mongoose.Schema({});
parentSchema.virtual('virt', {
type: mongoose.Schema.Types.ObjectId,
ref: 'nesteds',
foreignField: function ff(...args) {
console.log('ff this', this); // some
console.log('ff args', args); // none
return '_id';
},
localField: function lf(...args) {
console.log('lf this', this); // some
console.log('lf args', args); // some
return 'parent';
},
});
const NestedModel = mongoose.model('Nested', nestedSchema);
const ParentModel = mongoose.model('Parent', parentSchema);
(async () => {
await mongoose.connect(`mongodb://localhost:27017/`, {
dbName: 'verifyMASTER',
});
const parent1 = await ParentModel.create({});
const nested1 = await NestedModel.create({ parent: parent1._id });
const nested2 = await NestedModel.create({ parent: parent1._id });
const found = await ParentModel.findById(parent1._id).orFail().exec();
await found.populate('virt');
await mongoose.disconnect();
})(); where |
In 6.2.5, we'll call |
Do you want to request a feature or report a bug?
documentation
What is the current behavior?
Currently, i can not find more than 1 example of
match
being used in the documentation for virtual populate (the only example i could find)so i would like to request more documentation showcasing what this option can do, what arguments it has (when used as a function)
PS: does
foreignField
accept a function, when yes with what arguments?The text was updated successfully, but these errors were encountered: