开始使用mongo 发现一个问题,很难描述,请慢慢看代码
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 }
问题1
var d = t
是引用赋值吗 如果是的话,怎么样不使用引用赋值
delete d.password true > d { "_id" : ObjectId("5141b98723616e67f947f356"), "name" : "mongo" } > d.password=124 124 > d { "_id" : ObjectId("5141b98723616e67f947f356"), "name" : "mongo", "password" : 124, "password" : 124 }
问题2 我执行
delete d.password
返回 true 说明已经删除,为什么我再执行
d.password=124
会执行两次添加
> d { "_id" : ObjectId("5141b98723616e67f947f356"), "name" : "mongo", "password" : 124, "password" : 124 }
刚开始接触 不是很明白,希望有知道的说明下原因
Nicky
10 years, 6 months ago