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

Update an element in an array without changing internal order

    • Type: Icon: Question Question
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.2
    • Component/s: Shell
    • Labels:
      None
    • Environment:
      CentOs 6.4

      Hi
      I have a few documents with the following structure:
      {
      "_id" : 64293,
      "ispId" : 3,
      "slaId" : 489451,
      "type" : "VSAT",
      "data" : [

      { "oid" : "1.3.6.1.4.1.7352.3.5.11.5.36.1.3", "instance" : "1.1", "value" : "0" }

      ,

      { "instance" : "0", "oid" : "1.3.6.1.4.1.7352.3.5.11.4.21.3", "value" : "/Index.htm" }

      ,

      { "oid" : "1.3.6.1.4.1.7352.3.5.11.5.36.1.4", "instance" : "1.1", "value" : "0" }

      ,

      { "oid" : "1.3.6.1.4.1.7352.3.5.11.5.36.1.6", "instance" : "1.1", "value" : "10" }

      ,
      ...
      ]}
      I need to update all documents where the "oid" equals a certain value, and set the "value" to another value.
      I tried the following:
      db.committedManagedElements.update(

      {"type": "VSAT","data.oid":"1.3.6.1.4.1.7352.3.5.11.4.21.3"}

      ,{$set:{"data.$.value":"/Basic.htm"}},false,true)
      The result is that the field is updated but the internal order within the array component is changed for the updated. After update it is

      { "instance" : "0", "oid" : "1.3.6.1.4.1.7352.3.5.11.4.21.3", "value" : "/Basic.htm" }

      ,
      when I need it to be

      { "oid" : "1.3.6.1.4.1.7352.3.5.11.4.21.3", "instance" : "0", "value" : "/Basic.htm" }

      ,

      Is there a way to keep the order during update as well?
      Thank you
      Karin

            Assignee:
            Unassigned Unassigned
            Reporter:
            gile@gilat.com Karin Elazari
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: