Details
-
Bug
-
Resolution: Done
-
Major - P3
-
None
-
None
-
*Location*: https://docs.mongodb.org/v2.4/core/index-sparse/#index-type-sparse
*User-Agent*: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36
*Referrer*: https://docs.mongodb.org/v2.4/core/index-unique/
*Screen Resolution*: 2560 x 1440
*repo*: docs
*source*: core/index-sparse
*Location*: https://docs.mongodb.org/v2.4/core/index-sparse/#index-type-sparse *User-Agent*: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36 *Referrer*: https://docs.mongodb.org/v2.4/core/index-unique/ *Screen Resolution*: 2560 x 1440 *repo*: docs *source*: core/index-sparse
Description
The final statement on this page appears to be wrong:
```
However, this index would not permit adding the following documents:
db.scores.insert(
{ "userid": "PWWfO8lFs1", "score": 82 } )
db.scores.insert(
)
```
It would allow those documents because their score value is unique. I think you accidentally set the userid's to be similar to past inserted data rather than the scores. I tested this simply by entering the commands:
```
> db.scores.ensureIndex(
,
{ sparse: true, unique: true })
{ "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 }> db.scores.insert(
{ "userid": "PWWfO8lFs1", "score": 43 } )
WriteResult(
)
> db.scores.insert(
)
WriteResult(
)
> db.scores.insert(
)
WriteResult(
)
> db.scores.insert(
)
WriteResult(
)
> db.scores.insert(
)
WriteResult(
)
```