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

MongoImport Upsert doesn't work for empty arrays

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.6.9
    • Component/s: mongoimport
    • None

      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

       

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

              Created:
              Updated:
              Resolved: