Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-29526

Updating the specific array in nested subdocument

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • ALL

      Hello All,

      I have a similar situation I guess, the following is the sample Json document in which I need to query on.

      {
          "_id" : ObjectId("591d601fc9f360331cd4668c"),
          "Type" : "district",
          "GroupId" : "00000000-0000-0000-0000-000000000456",
          "Grades" : [ 
              {
                  "GroupId" : "gs00000000-0000-0000-0000-000000000452",
                  "Categories" : [ 
                      {
                          "Sequence" : 1,
                          "Low" : 0,
                          "High" : 99,
                          "Min" : 0,
                          "Max" : 0,
                      }, 
      				 {
                          "Sequence" : 1,
                          "Low" : 50,
                          "High" : 99,
                          "Min" : 0,
                          "Max" : 0,
                      }
                  ]
              }
          ],
          "NumberOfTypes" : 4,
          "CreatedDate" : ISODate("2017-05-18T08:49:35.433Z"),
          "LastModifiedDate" : ISODate("2017-05-26T16:12:52.093Z"),
          "Status" : true
      }
      

      I need to pick all the document where the value of "Low": 0 and change to 1. I am trying the following query

      db.BenchmarkDetails.update(
          {"Grades.Categories.Low" : 0},
          {$set : 
                  {"Grades.Categories.$.Low" : 1}
           }
           )
      

      This throwing the error

      cannot use the part (Grades of Grades.Categories.0.Low) to traverse the element.

            Assignee:
            kelsey.schubert@mongodb.com Kelsey Schubert
            Reporter:
            katakam.maniratnam@gmail.com Maniratnam Katakam
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: