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

Merge subdocuments in mongoimport

    XMLWordPrintable

Details

    • Investigation
    • Status: Accepted
    • Major - P3
    • Resolution: Unresolved
    • None
    • None
    • mongoimport
    • None

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated: