Note that there are some explanatory texts on larger screens.

plurals
  1. PODuplicate key error with mongodb 2dsphere unique index
    primarykey
    data
    text
    <p>I try to inserts geo points to mongodb with 2dsphere unique index, but it raises many duplicate key error.</p> <p>A simple reproduce demo:</p> <pre><code>&gt; version() 2.4.5 &gt; use geo &gt; db.test.ensureIndex( { loc : "2dsphere" }, unique=true ) &gt; db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.3736642, 23.04469194 ] }}) &gt; db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.3734775, 23.04609556 ] }}) E11000 duplicate key error index: geo.test.$loc_2dsphere dup key: { : "1f22000102222113" } </code></pre> <p>Why these totally different points raise duplicate key error?</p> <hr> <p>Update:</p> <p>I tried other tests, it seems to have something to do with accuracy.</p> <pre><code>&gt; db.test.ensureIndex( { loc : "2dsphere" }, unique=true ) &gt; db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.373, 23.044 ] }}) &gt; db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.373, 23.045 ] }}) E11000 duplicate key error index: geo.test.$loc_2dsphere dup key: { : "1f22000102222113" } &gt; db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.373, 23.046 ] }}) E11000 duplicate key error index: geo.test.$loc_2dsphere dup key: { : "1f22000102222113" } &gt; db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.373, 23.047 ] }}) E11000 duplicate key error index: geo.test.$loc_2dsphere dup key: { : "1f22000102222113" } &gt; db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.373, 23.048 ] }}) E11000 duplicate key error index: geo.test.$loc_2dsphere dup key: { : "1f22000102222113" } &gt; db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.373, 23.049 ] }}) </code></pre> <p>In this test 23.045 to 23.048 failed, only 23.044 23.049 succeed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload