【发布时间】:2014-05-29 22:08:14
【问题描述】:
这是我的命令行的输出。 您可以看到第一次尝试创建索引失败。 然后我只是将 loc-Field 重命名为坐标,它可以工作??? 有人可以向我解释一下吗。这似乎是一种奇怪的行为。
> db.nodes.find().limit(3)
{ "_id" : ObjectId("534d36b682beda5978db27c1"), "geo" : { "type" : "Point", "loc" : [ 9.7366511, 52.3711883 ] } }
{ "_id" : ObjectId("534d36b682beda5978db27c2"), "geo" : { "type" : "Point", "loc" : [ 9.7399576, 52.3691615 ] } }
{ "_id" : ObjectId("534d36b682beda5978db27c3"), "geo" : { "type" : "Point", "loc" : [ 9.7346094, 52.371738 ] } }
> db.nodes.ensureIndex({"geo":"2dsphere"})
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"ok" : 0,
"errmsg" : "Can't extract geo keys from object, malformed geometry?: { _id: ObjectId('534d36b682beda5978db27c1'), geo: { type: \"Point\", loc: [ 9.7366511, 52.3711883 ] } }",
"code" : 16755
}
> db.nodes.find().limit(3)
{ "_id" : ObjectId("534d36ea82be11ca6e9fb112"), "geo" : { "type" : "Point", "coordinates" : [ 9.7366511, 52.3711883 ] } }
{ "_id" : ObjectId("534d36ea82be11ca6e9fb113"), "geo" : { "type" : "Point", "coordinates" : [ 9.7399576, 52.3691615 ] } }
{ "_id" : ObjectId("534d36ea82be11ca6e9fb114"), "geo" : { "type" : "Point", "coordinates" : [ 9.7346094, 52.371738 ] } }
> db.nodes.ensureIndex({"geo":"2dsphere"})
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
【问题讨论】:
标签: mongodb indexing geometry geospatial geo