[SERVER-36999] mongo shell doesn't support inserting documents with duplicate field names Created: 05/Sep/18  Updated: 27/Oct/23  Resolved: 05/Sep/18

Status: Closed
Project: Core Server
Component/s: Tools
Affects Version/s: 3.6.7, 4.0.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Adam Milazzo Assignee: Nick Brewer
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows


Issue Links:
Related
related to SERVER-6439 Duplicate fields at the same level sh... Backlog
Operating System: ALL
Participants:

 Description   

Example shell output:

> db.dup.insert({_id:1, a:1, a:2})
WriteResult({ "nInserted" : 1 })
> db.dup.find()

{ "_id" : 1, "a" : 2 }

InsertMany has the same problem:

> db.dup.insertMany([\{_id:1, a:1, a:2},\{_id:2,a:1,a:2}])

{ "acknowledged" : true, "insertedIds" : [ 1, 2 ] }

> db.dup.find()

{ "_id" : 1, "a" : 2 } { "_id" : 2, "a" : 2 }

 Comments   
Comment by Nick Brewer [ 05/Sep/18 ]

admilazz Thanks for your report. This is expected behavior and is a result of how Javascript handles duplicate property names.

As the documentation notes, handling of duplicate fields differs depending upon the driver used.

The underlying behavior of duplicate fields being allowed is tracked here: SERVER-6439

-Nick

Generated at Thu Feb 08 04:44:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.