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

Save shell command allows multiple documents to be inserted

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 6.3.0-rc0
    • Affects Version/s: None
    • Component/s: Shell
    • Environment:
      Studio 3T for MongoDB
    • Fully Compatible
    • QE 2022-11-14, QE 2022-11-28

      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

      Unable to find source-code formatter for language: mongo. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      db.test.save(
      	{
      		"_id": 1,
      		"fruit": "apple 123"  	
      	}
      )
      

      Why is it allowed to upsert multiple documents?

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

              Created:
              Updated:
              Resolved: