You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Consider this nesting setup:
// nested.jsvarNestedPropDef={someProp: {type: String,default: ''},};varschema=newSchema(NestedPropDef,{minimize: false});schema.statics={getInstance(){varnestedObject=newNestedProp();nestedObject.someProp='something';console.log('[first log] value of nestedObject:',nestedObject);returnnestedObject;},});varNestedProp=mongoose.model('NestedProp',schema);exports.NestedPropDef=NestedPropDef;exports.NestedProp=NestedProp;
// parent-file.jsvarNestedPropDef=require('./nested').NestedPropDef;varNestedProp=require('./nested').NestedProp;varschema=newSchema({otherProp: {type: String,default: ''},nestedProp: NestedPropDef,});schema.methods.updateNestedProp=function(data,callback){this.nestedProp=NestedProp.getInstance();console.log('[second log] value of nestedProp:',this.nestedProp);this.otherProp: data.otherProp;console.log('[third log] value of this:',this);this.save(callback);});varParent=mongoose.model('Parent',schema);module.exports=Parent;
The current behavior is this:
[first log] value of nestedObject: {
someProp: 'something'
}
[second log] value of nestedProp: {}
[third log] value of this: {
otherProp: 'some value'
// nestedProp is missing
}
What is the expected behavior?
As of version 5.9.24, the log statements would be as follows:
[first log] value of nestedObject: {
someProp: 'something'
}
[second log] value of nestedProp: {
someProp: 'something'
}
[third log] value of this: {
otherProp: 'some value',
nestedProp: {
someProp: 'something'
}
}
I understand that using the schema of NestedProp would mostly restore the previous functionality, like this:
But this adds the _id field to nestedProp, which wasn't there previously. So the third log would be this:
[third log] value of this: {
otherProp: 'some value',
nestedProp: {
someProp: 'something',
_id: ...
}
}
Maybe that's a tiny and worthy sacrifice, and I know there's a way to disable the automatic addition of the _id, but my objective is to restore the previous functionality so other subtle bugs don't creep up on me. How can I restore the results I was seeing in 5.9.24? Or was I always nesting incorrectly (and Mongoose was just working with my incorrect nesting)?
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: 10 and 12
Mongoose: 5.10.3
The text was updated successfully, but these errors were encountered:
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Consider this nesting setup:
The current behavior is this:
What is the expected behavior?
As of version 5.9.24, the log statements would be as follows:
I understand that using the schema of
NestedProp
would mostly restore the previous functionality, like this:But this adds the
_id
field tonestedProp
, which wasn't there previously. So the third log would be this:Maybe that's a tiny and worthy sacrifice, and I know there's a way to disable the automatic addition of the
_id
, but my objective is to restore the previous functionality so other subtle bugs don't creep up on me. How can I restore the results I was seeing in 5.9.24? Or was I always nesting incorrectly (and Mongoose was just working with my incorrect nesting)?What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
The text was updated successfully, but these errors were encountered: