db.mongo.insert({name:'mongo'}); > var t=db.mongo.findOne(); > t { "_id" : ObjectId("5141b98723616e67f947f356"), "name" : "mongo" } > var d=t > d { "_id" : ObjectId("5141b98723616e67f947f356"), "name" : "mongo" } > d.password=123 123 > d { "_id" : ObjectId("5141b98723616e67f947f356"), "name" : "mongo", "password" : 123 } > t { "_id" : ObjectId("5141b98723616e67f947f356"), "name" : "mongo", "password" : 123 }
Question 1
var d = t
Is it a reference assignment? If so, how about not using a reference assignment?
delete d.password true > d { "_id" : ObjectId("5141b98723616e67f947f356"), "name" : "mongo" } > d.password=124 124 > d { "_id" : ObjectId("5141b98723616e67f947f356"), "name" : "mongo", "password" : 124, "password" : 124 }
Question 2: I will execute it.
delete d.password
Returns true to indicate that it has been deleted, why should I execute it again
d.password=124
Two additions are performed
> d { "_id" : ObjectId("5141b98723616e67f947f356"), "name" : "mongo", "password" : 124, "password" : 124 }
At first contact is not very clear, hope to know the reason
First question … because the two entries are the same
ObjectId
Therefore, it is regarded as the same article. …Although it is not actually a reference assignment, you can understand it this way. …
The second question cannot be reproduced, so I do not know …