문제

This is my first question here so please be patient with me if its not asked very well or if my english is bad.

I am trying do Geospatioal Querys in MongoDB in Node.js.

This query works just fine

collection.find( { loc : { $geoWithin :
    { $centerSphere :
        [ [ point.coordinates[0], point.coordinates[1]] , getRadiusMeters(radius) ]
    } } } )

but when i try to do the same with $nearSphere:

collection.find(  { loc :{ $nearSphere :
            { $geometry :
            { type : "Point" ,
                coordinates : [ point.coordinates[0], point.coordinates[1]] } ,
                $maxDistance : getRadiusMeters(radius)
            } } } )

I get the following Error:

{ [MongoError: can't find any special indices: 2d (needs index), 2dsphere (needs index),  for: { loc: { $nearSphere: { $geometry: { type: "Point", coordinates: [ 6.128777, 49.596792 ] }, $maxDistance: 10000 } } }] name: 'MongoError' }

I think i have the right indexes. Here are my Indexes:

> db.realtrip.getIndexes()
[
    {
            "v" : 1,
            "key" : {
                    "_id" : 1
            },
            "ns" : "test.realtrip",
            "name" : "_id_"
    },
    {
            "v" : 1,
            "key" : {
                    "loc" : "2dsphere"
            },
            "ns" : "test.realtrip",
            "name" : "loc_2dsphere"
    },
    {
            "v" : 1,
            "key" : {
                    "tags" : 1
            },
            "ns" : "test.realtrip",
            "name" : "tags_1"
    },
    {
            "v" : 1,
            "key" : {
                    "loc" : "2d"
            },
            "ns" : "test.realtrip",
            "name" : "loc_2d"
    }
]

I cant find what I am doing wrong. The $centerSphere Query works just fine only the $nearSphere Query gives me Errors.

도움이 되었습니까?

해결책

it turned out my bug was related to this issue Bugreport Mongodb

Updating my mongodb solved it. Now the code works as expected.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top