[SERVER-6873] Inserting a unique value into a specific position in an array Created: 27/Aug/12  Updated: 07/Mar/14  Resolved: 27/Aug/12

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Jan Riechers Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-2363 $push/$pushAll support for insertion ... Closed
Related
Participants:

 Description   

Inserting an item of any type into a specific postion into existing array structure

Currently $push only appends data to an array.
But there is no function to insert an array into a specific postion.

Example data (Python array)

Before:
[ [Item1, 0, 0], [Item2, 0, 0].. ] # Array items inside an array

Command for example can be
{ '$insert':

{ 'myArray.1': [item3, 0,0 ] }

} # At position 1 of the myArray

Result:
[ [Item1, 0,0], [Item3, 0,0], [Item2, 0,0] ]

$push is out of question as the data should be inserted to keep a order of the items.



 Comments   
Comment by Eliot Horowitz (Inactive) [ 27/Aug/12 ]

Ah, you want insert at a given position.

Comment by Jan Riechers [ 27/Aug/12 ]

Hi,

but the $set-operator will overwrite an item, I want to add an item without removing/overwriting the one living at the particular position.

Comment by Eliot Horowitz (Inactive) [ 27/Aug/12 ]

You can $set

{ $set :

{ "myArray.1" : ... }

}

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