Mongodb stores data of similar structure:
{
_id:"10001",
array:[
{sub_id:"1",sub_array:["text11","text12","text13"]},
{sub_id:"2",sub_array:["text21","text22","text23"]},
{sub_id:"3",sub_array:["text31","text32","text33"]}
]
}
If you add content directly to the array, it is very simple, just use the $push operator.
But if I want to push several strings into sub_array with sub_id 2, how should I locate them?
I can’t.
Must first
find
, according to the query results to locatesub_id
Which is the array (assuming that the label in the title is 1), the last update{"array.1.sub_array": {$push: "text24"}}
.