[DOCS-7813] Sparse Index with Unique Constraint property not working as given in docs) Created: 05/May/16  Updated: 03/Nov/17  Resolved: 18/May/16

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Bug Priority: Major - P3
Reporter: vishal arora Assignee: Unassigned
Resolution: Done Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

we are using mactentossh for running mongo

Location: https://docs.mongodb.org/manual/core/index-sparse/
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36
Referrer: https://docs.mongodb.org/manual/core/index-partial/
Screen Resolution: 1280 x 1024


Participants:
Days since reply: 7 years, 39 weeks, 1 day ago

 Description   

AS per given docs index with unique will insert a new document if i have the unique value same but as i found result is opposite that it is not allowing to insert

E1100 duplicate error i am getting

Reporter: vishal
E-mail: aroravishal91@gmail.com



 Comments   
Comment by Kay Kim (Inactive) [ 18/May/16 ]

Hi – thanks for filing this ticket. On the page, we state that (bolded here just to better highlight)

An index that is both sparse and unique *prevents* collection from having documents with duplicate values for a field but allows multiple documents that *omit* the key.

So, a unique, sparse index will not allow for duplicate keys; however, if the documents are missing the key, then it will allow the insert.

So, if unique, sparse index on field x exists, you can insert into some collection collA:

{ x: 1 } { y: 0 } { y: 0 } { y: 1 }

but not

{ x: 1}

again.

If the x index were only unique and not sparse, you could insert into some other collection collB:

{ x: 1} { y: 0 }

<-- the x value would be null.
but not:

{ y: 0 }

or

{ y: 1 }

since these would both have an x value of null and conflict with the already inserted

{ y: 0 }

document.

Hope this helps.

Regards,

Kay

Generated at Thu Feb 08 07:55:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.