The problem of incomplete batch update of mongodb subdocuments.

  mongodb, question

There are the following data structures

{
 "_id" : ObjectId("55dc1454f754a3342000002c"),
 "title": "derailment is like whirlwind, fire prevention, theft prevention and small three prevention",
 "games" : [
 {
 "id" : 1615,
 "name_zh": "Meet you through time and space",
 "typename": "Leisure and Educational"
 },
 {
 "id" : 6356,
 "name_zh": "Love Story 3: Wings of Dreams",
 "typename": "Role Playing"
 },
 {
 "id" : 6505,
 "name_zh": "Love Story: Blue Memories",
 "typename": "Role Playing"
 }
 ]
 }
 
 /* 2 */
 {
 "_id" : ObjectId("55dc145ef754a3342000002d"),
 "title": "on a hot summer day, follow me High and earth-shaking!"  ,
 "games" : [
 {
 "id" : 1128,
 "name_zh": "Pursuing Beasts",
 "typename": "Role Playing"
 },
 {
 "id" : 3276,
 "name_zh": "World Zombie Alliance",
 "typename": "Strategy Game"
 },
 {
 "id" : 10360,
 "name_zh": "Green Ninja Frog Year",
 "typename": "Role Playing"
 }
 ]
 }
 
 /* 3 */
 {
 "_id" : ObjectId("55dc1467f754a3342000002e"),
 "title": "Simple but not Simple Pixel Game Series",
 "games" : [
 {
 "id" : 1557,
 "name_zh": "My World",
 "typename": "Leisure and Educational"
 },
 {
 "id" : 6228,
 "name_zh": "Localization of Pixel Underground City",
 "apk_size" : "5.39M",
 "typename": "Role Playing"
 },
 {
 "id" : 6230,
 "name_zh": "Chinese Version of the Land of Evolution",
 "typename": "Role Playing"
 }
 ]
 }

Run bulk update statement:

Db.getcollection ('xxxxx'). update ('games.typename':' role play' },{'$set':{'games.$.typename':' role'} }},0,1)

The results show that the batch update is incomplete. The results are as follows:

{
 "_id" : ObjectId("55dc1454f754a3342000002c"),
 "title": "derailment is like whirlwind, fire prevention, theft prevention and small three prevention",
 "games" : [
 {
 "id" : 1615,
 "name_zh": "Meet you through time and space",
 "typename": "Leisure and Educational"
 },
 {
 "id" : 6356,
 "name_zh": "Love Story 3: Wings of Dreams",
 "typename": "role"
 },
 {
 "id" : 6505,
 "name_zh": "Love Story: Blue Memories",
 "typename": "Role Playing"
 }
 ]
 }
 
 /* 2 */
 {
 "_id" : ObjectId("55dc145ef754a3342000002d"),
 "title": "on a hot summer day, follow me High and earth-shaking!"  ,
 "games" : [
 {
 "id" : 1128,
 "name_zh": "Pursuing Beasts",
 "typename": "role"
 },
 {
 "id" : 3276,
 "name_zh": "World Zombie Alliance",
 "typename": "Strategy Game"
 },
 {
 "id" : 10360,
 "name_zh": "Green Ninja Frog Year",
 "typename": "Role Playing"
 }
 ]
 }
 
 /* 3 */
 {
 "_id" : ObjectId("55dc1467f754a3342000002e"),
 "title": "Simple but not Simple Pixel Game Series",
 "games" : [
 {
 "id" : 1557,
 "name_zh": "My World",
 "typename": "Leisure and Educational"
 },
 {
 "id" : 6228,
 "name_zh": "Localization of Pixel Underground City",
 "apk_size" : "5.39M",
 "typename": "role"
 },
 {
 "id" : 6230,
 "name_zh": "Chinese Version of the Land of Evolution",
 "typename": "Role Playing"
 }
 ]
 }

Can you tell me how to write the update statement in order to completely update all eligible data?

Mongo’s $ operator refers to the first matched array element, so only one array object can be replaced. If all matching objects of the embedded array are to be modified, it can be modified by querying and then written. Currently, there is no operator that can directly implement this function.