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?
Modifying the object in setters behaves strangely
Fields created in set functions are not added to the object
If the current behavior is a bug, please provide the steps to reproduce.
constmongoose=require('mongoose')constSchema=mongoose.Schemaconstdb=mongoose.createConnection()constNameSchema=newSchema({full: {type: String,set: function(v,x,y){// One way to set valuesthis.set('first','XXX')// Another waythis.last='YYY';// Something weirdthis.weird='ZZZ'// Log current valueconsole.log('Current value',this)// { first: 'XXX', last: 'YYY' } // Logs this on each occasionreturnv+' BBB';}},first: String,last: String,},{_id: false,strict: false})constUser=mongoose.model('user',newSchema({name: {type: NameSchema,default: {},}},{_id: false,strict: false}))test('(0) User set name',done=>{consts=newUser()s.name={full: 'AAA',other: 'ZZZ'}console.log(s)// { name: { full: 'AAA BBB', other: 'ZZZ' } }done()})test('(1) User set name',done=>{consts=newUser({name: {full: 'AAA',other: 'ZZZ'}})console.log(s)// { first: 'XXX', last: 'YYY', full: 'AAA BBB', other } }done()})test('(2) User set name',done=>{consts=newUser()// s.name = {}s.name.full='AAA's.name.other='ZZZ';console.log(s)// { first: 'XXX', last: 'YYY', full: 'AAA BBB' } }done()})
Result in a table:
name.full
name.first
name.last
name.weird
name.other
Test 0
AAA BBB
-
-
-
ZZZ
Test 1
AAA BBB
ZZZ
YYY
-
ZZZ
Test 2
AAA BBB
ZZZ
YYY
-
-
What is the expected behavior?
Firstly I expect test (0) to produce the same result as test (1) and test (2). Please note that everything works very differently if you comment out default: {} property (and uncomment //s.name = {}.
Secondly I'd expect that on each of the tests the property weird to exist.
Please mention your node.js, mongoose and MongoDB version.
Node: 11.10.0
Mongoose: 5.4.17
MongoDB: 3.6.9
The text was updated successfully, but these errors were encountered:
vkarpov15
added
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
labels
Mar 24, 2019
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
If the current behavior is a bug, please provide the steps to reproduce.
Result in a table:
What is the expected behavior?
Firstly I expect
test (0)
to produce the same result astest (1)
andtest (2)
. Please note that everything works very differently if you comment outdefault: {}
property (and uncomment//s.name = {}
.Secondly I'd expect that on each of the tests the property
weird
to exist.Please mention your node.js, mongoose and MongoDB version.
Node: 11.10.0
Mongoose: 5.4.17
MongoDB: 3.6.9
The text was updated successfully, but these errors were encountered: