-
-
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
Support virtual options.match
#8749
Comments
I'm unable to repro this issue, the below script demonstrates that 'use strict';
const mongoose = require('mongoose');
mongoose.set('useFindAndModify', false);
mongoose.set('debug', true);
const { Schema } = mongoose;
run().catch(err => console.log(err));
async function run() {
await mongoose.connect('mongodb://localhost:27017/test', {
useNewUrlParser: true,
useUnifiedTopology: true
});
await mongoose.connection.dropDatabase();
const projectSchema = new Schema({
group: { type: Schema.Types.ObjectId, ref: 'Group' },
status: String
});
const Project = mongoose.model('Project', projectSchema, 'Project');
const groupSchema = new Schema({})
groupSchema.virtual('projects', {
ref: 'Project',
localField: '_id',
foreignField: 'group',
justOne: false,
// @todo not working
options: {
match: {
status: { $ne: '-1' }
}
}
});
const groupModel = mongoose.model('Group', groupSchema, 'Group');
const g = await groupModel.create({});
await Project.create({ status: 'foo', group: g });
await Project.create({ status: '-1', group: g });
const doc = await groupModel.findOne().populate({ path: 'projects' });
console.log(doc.toObject({ virtuals: true }));
} Output:
Please modify the above script to demonstrate the issue you're seeing. |
I'm using typescript and getting a type unassignable error when trying to use options.match:
gives me:
If match should work in virtuals, is there something missing in the typescript declarations? |
options.match
Fixed by 5c0140c, I typo-ed the issue number in the commit message. |
Do you want to request a feature or report a bug?
BUG
What is the current behavior?
Schema.prototype.virtual
options.options.match
oroptions.match
not working.Workaround: add
match
to populate options.If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
Exclude some project in
projects
.What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
NodeJS12.12.0 Mongoose5.9.7
The text was updated successfully, but these errors were encountered: