0
我使用Mongo DB来存储坐标,我想使用$ near query查找坐标,但没有结果,有人可以帮我吗? 这里是我的蒙戈DB
> db.course.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "dev.course"
},
{
"v" : 1,
"key" : {
"coordinate" : "2dsphere"
},
"name" : "coordinate_2dsphere",
"ns" : "dev.course",
"2dsphereIndexVersion" : 3
}
]
指数这里是我的数据
{ "_id" : 1, "schoolId" : 0, "longitude" : 0, "latitude" : 0, "coordinate" : [ 0, 0 ], "courseTitle" : "暂无", "imageIds" : "[]", "videoIds" : "[]", "startTime" : "", "teacherIds" : "[]", "gradeIds" : "[]", "subjectId" : 0, "expense" : 0, "followNum" : 0, "courseStatus" : "NOSTART", "authorizationStatus" : "NO", "rejectReason" : "", "createTime" : "2017-01-01 16:58:22" }
我查询
db.course.find({"coordinate": {"near": [123, 20]}})
没有结果。有谁能够帮助我?
它的作品,非常感谢你!如果我使用2dsphere索引文件,那么我必须使用GeoJSON格式,但如果我使用2d索引文件,那么我可以使用GesJSON和传统坐标对,是吗? – Minky
你能告诉我这个查询有什么问题:> db.course.find({“coordinate”:{“$ near”:[123,20],“$ limit”:100}}) – Minky
是2d用于遗留坐标,2dspere为GeoJSon格式。你可以用'db.course.find({“coordinate”:{“$ near”:[123,20]}})来限制结果的数量,限制(100)' –