地理空间索引数组格式不正确

地理空间索引数组格式不正确

本文介绍了MongoDB:地理空间索引数组格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试设置以在MongoDB上使用地理空间索引时,我遇到了错误消息,即位置数组的格式不正确.

While trying to setup to use the Geospatial Index on MongoDB, I run into the error message that the location array is not in the correct format.

这是我的收藏集测试".

This is my collection "test".

{
    "_id" : ObjectId("4f037ac176d6fdab5b00000a"),
    "CorporateId" : "XYZ12345",
    "Places" : [
           {

                   "Location" : {
                           "Longitude" : "50.0",
                           "Latitude" : "50.0"
                   },
                   "ValidFrom" : "2011-11-01 00:00:00",
                   "ValidTo" : "2021-12-31 00:00:00",
                   "itemCount" : "1"
           }
    ]
}

一旦我运行此代码.

db.test.ensureIndex({"Places.Location": "2d"});

我收到此错误消息

我的假设是长/短需要是一个数字.当前它是一个对象.

My assumption is that the Long/Lat needs to be a number.Currently it is an object.

typeof db.test.Places.Location.Longitude -> Object
typeof db.test.Places.Location -> Object

我的问题是,由于我还是MongoDB的新手,所以我真的不知道如何以最佳方式解决此问题.

My problem is that since I am still quite new to MongoDB, I don't really know how to approach this problem in the best way.

推荐答案

在传递字符串时,Mongodb期望坐标的数字.

Mongodb expects numbers for the coordinates while you passed in a string.

"Location" : {
                       "Longitude" : 50.0, // <<<<<<<<<<<<<< use numbers instead
                       "Latitude" : 50.0
               },

请参阅 http://www.mongodb.org/display/DOCS/Geospatial+Indexing 详细信息.

这篇关于MongoDB:地理空间索引数组格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 20:40