我尝试用2dsphere唯一索引插入地理点到mongodb,但它引发了许多重复键错误。与mongodb 2dsphere独特索引重复的关键错误
一个简单的重现演示:
> version()
2.4.5
> use geo
> db.test.ensureIndex({ loc : "2dsphere" }, unique=true)
> db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.3736642, 23.04469194 ] }})
> db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.3734775, 23.04609556 ] }})
E11000 duplicate key error index: geo.test.$loc_2dsphere dup key: { : "1f22000102222113" }
为什么这些完全不同的点,提高重复键错误?
更新:
我试过其他的测试,它似乎有事情做准确。
> db.test.ensureIndex({ loc : "2dsphere" }, unique=true)
> db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.373, 23.044 ] }})
> db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.373, 23.045 ] }})
E11000 duplicate key error index: geo.test.$loc_2dsphere dup key: { : "1f22000102222113" }
> db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.373, 23.046 ] }})
E11000 duplicate key error index: geo.test.$loc_2dsphere dup key: { : "1f22000102222113" }
> db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.373, 23.047 ] }})
E11000 duplicate key error index: geo.test.$loc_2dsphere dup key: { : "1f22000102222113" }
> db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.373, 23.048 ] }})
E11000 duplicate key error index: geo.test.$loc_2dsphere dup key: { : "1f22000102222113" }
> db.test.insert({"loc" : { "type" : "Point", "coordinates" : [ 113.373, 23.049 ] }})
在此测试中23.045至23.048失败,只有23.044 23.049成功。
让我试试这个 - 哪个版本的MongoDB是这样的? – Derick
@Derick版本添加到问题。 – lxyu