Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-2976

Merge subdocuments in mongoimport

    • Type: Icon: Investigation Investigation
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: mongoimport
    • None
    • 1,123

      Currently mongoimport's merge mode will $set the entire document from a CSV. This means that it overwrites subdocuments that already exist. It might be useful to merge subdocuments. For example, this CSV:

      _id,a.b,a.c
      1,2,3

      With this document in the database:

      {
          _id: 1,
          a: {
              d: 4
          }
      } 

      currently results in:

      {
          _id: 1,
          a: {
              b: 2,
              c: 3
          }
      } 

      while we might want:

      {
          _id: 1,
          a: {
              b: 2,
              c: 3,
              d: 4
          }
      } 

      We can do the following to set subdocument fields:

      {$set: {"a.b": 2}}

      but we will need separate handling for arrays. Merging arrays would also cause an issue with ordering since the CSV specifies the exact position of elements in the array.

            Assignee:
            Unassigned Unassigned
            Reporter:
            tim.fogarty@mongodb.com Tim Fogarty
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: