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

MongoImport Upsert doesn't work for empty arrays

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Cannot Reproduce
    • Affects Version/s: 3.6.9
    • Fix Version/s: None
    • Component/s: mongoimport
    • Labels:
      None

      Description

      Insert a new document in MongoDB

      Example:

      db.collection.insert({"type":"Test","uid":"sampleUID", "items":[]})
      

      Use mongoimport tool to import a JSON  file (test.json) which has a record for the same sampleUID and type Test

      {"type":"Test","uid":"sampleUID", "items":[{"itemId":"1234","itemId":"4444"]}

       
      mongoimport --db dbName -c collectionName --mode upsert --upsertFields uid,type --type json --file test.json
      

       

      Result:

      Two documents present in MongoDB for the same uid and type

      {"_id" : ObjectId("5b6c3df492edb6fcb616feb7"),"type":"Test","uid":"sampleUID", "items":[{"itemId":"1234","itemId":"4444"]}
       
      {"_id" : ObjectId("5b6c3df492edb6fcb616feb6"),"type":"Test","uid":"sampleUID", "items":[]}
      

      Expected:

      This was an upsert operation, so the original empty list should have been updated instead of creating a new list

       

        Attachments

          Activity

            People

            Assignee:
            daniel.hatcher Danny Hatcher (Inactive)
            Reporter:
            lakshmi1234 Lakshmi Madhavarao
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: