[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: |
|
||||||||
| Operating System: | ALL | ||||||||
| Steps To Reproduce: | Step1- db.myCol.insert( {visitor_id:1,name:"hello",name:"hello1"}) ) |
||||||||
| 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"}) ) Query2-db.myCol.find( {visitor_id:1,name:"hello"}) ) 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 ] | ||
|
Thank you for the report. This is expected behavior, and is a result of how javascript objects/dicts work:
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, |