[SERVER-24048] Value missing in case of Duplicate Field Name Insertion Created: 04/May/16  Updated: 04/May/16  Resolved: 04/May/16

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.3.4
Fix Version/s: None

Type: Bug Priority: Trivial - P5
Reporter: pravin dwiwedi Assignee: Kelsey Schubert
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

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

Step1- db.myCol.insert(

{visitor_id:1,name:"hello",name:"hello1"}

)
Step2- db.myCol.find(

{visitor_id:1}

)

Participants:

 Description   

I have inserted a document with duplicate field name. While find, it is not giving both field. it is giving the last field only. This may mislead to the developers. If it is not giving the both fields then it should not allow to insert duplicate fields.

db.myCol.insert(

{visitor_id:1,name:"hello",name:"hello1"}

)
Query1-
db.myCol.find(

{visitor_id:1}

)
result--

{ "_id" : ObjectId("572a2b7052c7b442f853c135"), "visitor_id" : 1, "name" : "hello1" }

Query2-db.myCol.find(

{visitor_id:1,name:"hello"}

)
result--
None
Query3- db.myCol.find(

{visitor_id:1,name:"hello1"}

)
result--

{ "_id" : ObjectId("572a2b7052c7b442f853c135"),"visitor_id" : 1, "name" : "hello1" }

So in either of the query only last field(from duplicate) appears. Why is it not showing both the fields?



 Comments   
Comment by Kelsey Schubert [ 04/May/16 ]

Hi 2k.pravin@gmail.com,

Thank you for the report. This is expected behavior, and is a result of how javascript objects/dicts work:

> x = {a:2, a:1}
{a:1}

You cannot have repeated fields of the same name at the same level. For additional information please see mozilla's documentation on duplicate property names. As a result of this behavior, only the second property is inserted into the MongoDB server, which explains the output you observe.

Please note that the way duplicate field names are handled differs depending on the driver used, please review SERVER-6439 for more information.

Kind regards,
Thomas

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