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

Push element in any position of array in the subdocument

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 2.6.0
    • Fix Version/s: None
    • Component/s: Write Ops
    • Labels:
      None
    • Operating System:
      ALL

      Description

      In MongoDB 2.6 we can use $position modifier to specifies the location in the array during update of an array in a document. But I would like to insert in an array in a subdocument.

      // Document schema:
      {  subdoc: {
          array: ['0', '1', '2', '5', '6'] } }
       
      // The following update pushes the elements in the end of array..
      db.collection.update(
         { _id: tsId },
         {$push: { 'subdoc.array': { $each:['3', '4'], $position:2 } }});
       
      // So, the result is
      {  subdoc: {
          array: ['0', '1', '2', '5', '6', '3', '4'] }}
       
      // But I expect
      {  subdoc: {
          array: ['0', '1', '2', '3', '4', '5', '6'] }}

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: