Novice asks mongodb to update documentation.
The data for the existing collection named user is as follows
{
name:"abc",
people:{
student:{
stu_name:"YYW",
stu_num:12345
}
}
}
Now I’m going to add a field named stu_sex under people.student. What kind of statement do you want to use? It’s the first time for a novice to contact mongodb. Thank you for your advice.
Assuming that there is only one 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 a primary key of _id, put the above
{name: 'abc'}
Replace with the corresponding selector