Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb Mongo 3.0.5-无法在多边形上创建索引_Mongodb_Indexing_Geospatial - Fatal编程技术网

Mongodb Mongo 3.0.5-无法在多边形上创建索引

Mongodb Mongo 3.0.5-无法在多边形上创建索引,mongodb,indexing,geospatial,Mongodb,Indexing,Geospatial,我在Mongo 3.0.5上的一个集合中创建了此文档 db.s.insert( {_id: "Poly1", shape: {type: "Polygon", coordinates: [[ [3,1], [1,2], [5,6], [9,2], [4,3], [3,1] ]] } }) 然后我尝试在它上面创建一个2dshere索引 db.s.createIndex({"shape.coordinates" : "2dsphere"}, {bits:26}); 这就给了我这个错误 "err

我在Mongo 3.0.5上的一个集合中创建了此文档

db.s.insert( {_id: "Poly1", shape: {type: "Polygon", coordinates: [[ [3,1], [1,2], [5,6], [9,2], [4,3], [3,1] ]] } })
然后我尝试在它上面创建一个2dshere索引

db.s.createIndex({"shape.coordinates" : "2dsphere"}, {bits:26});
这就给了我这个错误

 "errmsg" : "exception: Can't extract geo keys: { _id: \"Poly1\", shape: { type: \"Polygon\", coordinates: [ [ [ 3.0, 1.0 ], [ 1.0, 2.0 ], [ 5.0, 6.0 ], [ 9.0, 2.0 ], [ 4.0, 3.0 ], [ 3.0, 1.0 ] ] ] } }  Point must only contain numeric elements",

以下是上手册页中与此处相关的内容:

2dsphere索引支持存储为GeoJSON对象和传统坐标对的数据(另请参见2dsphere索引字段限制)。对于传统坐标对,索引将数据转换为GeoJSON点。有关支持的GeoJSON对象的详细信息,请参阅GeoJSON对象

因此,当提到传统坐标结构时,这里的两个主要单词是“pair”,其中可以是一个数组,也可以是一组经度和纬度的键值。另一个关键词是“点”,即传统坐标对的存储方式。事实上,在这种形式下,它只是一个“点”对象

您的数据包含GeoJSON格式和“多边形”,这最终意味着您在“错误的位置”编制索引。请改用GeoJSON的根:

db.s.createIndex({“shape”:“2dsphere”});
然后创建索引并按设计工作

此外,我建议在您对索引的工作方式更加熟悉之前,不要使用索引上的其他设置。启动并运行一些查询,然后更改设置并观察效果