[SERVER-35988] MongoDB show duplicate key is null? Created: 06/Jul/18 Updated: 14/Aug/18 Resolved: 09/Jul/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 3.6.2 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | JONGCHANA PHUWASATE | Assignee: | Stennie Steneker (Inactive) |
| 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: | Run this command
|
||||
| Participants: | |||||
| Description |
|
I got the dup key message when I executed this.
|
| Comments |
| Comment by JONGCHANA PHUWASATE [ 09/Jul/18 ] |
|
Thank you for your information. |
| Comment by Stennie Steneker (Inactive) [ 09/Jul/18 ] |
|
jongchana.phuwasate This is the expected case if you have defined a unique index which is non-sparse: documents missing a value for the field with the unique index will have an indexed value of null. This means that only a single document in the collection can be missing the unique field. The duplicate key message includes the index name and key violation:
In this example, the collection setup in database testdb has a unique index called name. The attempted upsert failed because the name value was missing and there was already a document in this collection with a missing or null value for name. If you want to use a unique index without requiring the field to be present you need to recreate the index with the sparse property or a partialFilterExpression with an $exists:true match on the unique field name. Regards, |
| Comment by JONGCHANA PHUWASATE [ 06/Jul/18 ] |
|
I found other indexes on that collection have been set "unique" to be "true" (exclude _id) then it shows error. Please add more information which index that duplicated for a guideline to investigate. |