mongodb 文档更新
为情所困
为情所困 2017-05-02 09:22:15
0
1
563

新手请教mongodb更新文档。
现有collection名为 user的数据如下
{

name:"abc",
people:{
       student:{
           stu_name:"YYW",
           stu_num:12345
       }     
}

}

现在我要在people.student下添加一个名为stu_sex的字段,请问用什么样的语句,新手第一次接触mongodb,谢谢指教。

为情所困
为情所困

reply all(1)
大家讲道理

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template