-
-
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
Virtual fields toJSON does not work #5473
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
schema.virtual("x")
.get(function getX() {
return this.test.x;
})
.set(function setX(x) {
this.test.x = x;
}); |
Confirmed, thanks for the detailed repro script. Will fix ASAP. const mongoose = require('mongoose');
const schema = new mongoose.Schema({
some_field: Number,
}, {
toObject: { virtuals: true },
toJSON: { virtuals: true },
})
schema.virtual('test.a', function() {
return 1;
});
schema.virtual('test.b', function() {
return 2;
})
const Model = mongoose.model('Test', schema);
///
console.log((new Model()).toJSON()); // don't see test object |
vkarpov15
added
the
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
label
Jul 18, 2017
vkarpov15
added a commit
that referenced
this issue
Jul 25, 2017
@vkarpov15 u said 4 yrs ago that it will be fixed asap, but why is the bug still there? |
@sayantan300 please open a new issue and follow the issue template. This issue has been fixed for years and we have the tests to prove it. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Do you want to request a feature or report a bug?
Bug.
What is the current behavior?
What is the expected behavior?
but when
model.test.a
-> works, toJSON -> notPlease mention your node.js, mongoose and MongoDB version.
Mongoose: 4.11.3
NodeJS: 7.6.0
The text was updated successfully, but these errors were encountered: