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

Save shell command allows multiple documents to be inserted

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor - P4 Minor - P4
    • 6.3.0-rc0
    • None
    • Shell
    • Studio 3T for MongoDB
    • Fully Compatible
    • QE 2022-11-14, QE 2022-11-28

    Description

      According to this article https://docs.mongodb.com/manual/reference/method/db.collection.save/

      save does not support an array of documents but I could insert multiple documents as follows

      db.test.save(
      	[
      		{
      			"_id": 1,
      			"fruit": "apple"  	
      		},
      		{
      			"_id": 2,
      			"fruit": "banana"  	
      		}
      	]
      )
      

      Now if I run the below command to add '123' at the end of the fruit names, then the save throws duplicate key error. In fact this should have been an upsert since the '_id's are the same.

      db.test.save(
      	[
      		{
      			"_id": 1,
      			"fruit": "apple 123"  	
      		},
      		{
      			"_id": 2,
      			"fruit": "banana 123"  	
      		}
      	]
      )
      

      If I save just a single document then the upsert works as expected

      db.test.save(
      	{
      		"_id": 1,
      		"fruit": "apple 123"  	
      	}
      )
      

      Why is it allowed to upsert multiple documents?

      Attachments

        Activity

          People

            sebastien.mendez@mongodb.com Sebastien Mendez
            chaughulenaynishp@gmail.com Naynish Chaughule
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: