新手请教mongodb更新文档。现有collection名为 user的数据如下{
name:"abc", people:{ student:{ stu_name:"YYW", stu_num:12345 } }
}
现在我要在people.student下添加一个名为stu_sex的字段,请问用什么样的语句,新手第一次接触mongodb,谢谢指教。
Suppose there is only such a piece of data in your collection, a feasible code is as follows
db.user.update({name: 'abc'}, {$set: {'people.student.stu_sex': 'male'}});
If your data actually has the primary key _id, replace the above
{name: 'abc'}
Replace with the corresponding selector
Suppose there is only such a piece of data in your collection, a feasible code is as follows
If your data actually has the primary key _id, replace the above
Replace with the corresponding selector