[SERVER-12412] Update an element in an array without changing internal order Created: 20/Jan/14  Updated: 20/Jan/14  Resolved: 20/Jan/14

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.4.2
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Karin Elazari Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

CentOs 6.4


Issue Links:
Duplicate
duplicates SERVER-2592 The fields in a document are reordere... Closed
Participants:

 Description   

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



 Comments   
Comment by Scott Hernandez (Inactive) [ 20/Jan/14 ]

dup of SERVER-2592

Generated at Thu Feb 08 03:28:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.