[英]How to append attribute for object in Mongodb?
Example: 例:
user : {
"user_name" : "chicken_01",
"password" : "123456",
"skills" : {
"PHP" : 7.0,
"NodeJs" : 8.0,
"MongoDB" : 8.0
}
}
I want to add "HTML/CSS" : 8.0
to "skills"
inner object. 我想将
"HTML/CSS" : 8.0
到"skills"
内部对象。 What is the proper way to do it? 正确的做法是什么? Thank you!
谢谢!
is it like JS? 像JS吗? if yes :
如是 :
var userObj= JSON.parse(user);
userObj.skills.HTMLCSS = 8.0;
user = JSON.stringify(userObj);
db.users.update(
{'user_name' : 'chicken_01'},
{'$set' :
{
"skills.HTML/CSS":8.0
}
})
Except with the name of your collection and not db.users
. 除了集合名称而不是
db.users
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.