Friday, May 18, 2018

unable to find index for $geoNear query while using Laravel and MongoDB using Moloquent - development

unable to find index for $geoNear query while using Laravel and MongoDB using Moloquent

I am using the Moloquent model with Laravel 5.6. here is my collection record given below:-

{
    "_id" : ObjectId("5afe619dbe0b8d0e5876b16b"),
    "name" : "Central Park",
    "categories" : [ 
        "4d4b7105d754a06376d81259", 
        "4bf58dd8d48988d116941735", 
        "4bf58dd8d48988d119941735", 
        "4d4b7105d754a06376d81259", 
        "4bf58dd8d48988d116941735", 
        "4bf58dd8d48988d119941735", 
        "4d4b7105d754a06374d81259", 
        "4bf58dd8d48988d16d941735"
    ],
    "loc" : {
        "type" : "Point",
        "coordinates" : [ 
            88.4166612820784, 
            22.5835157504658
        ]
    }
}

I am running this query from the Laravel controller.

$users = MongoTest::where('loc', 'near', [
                    '$geometry' => [
                        'type' => 'Point',
                        'coordinates' => [
                            $longitude,
                            $latitude,
                        ],
                    ],
                    '$maxDistance' => 10,
                ])->get();

print_r($users);

I am getting this error:-

error processing query: ns=tkit.testTree: GEONEAR  field=loc maxdist=10 isNearSphere=0
Sort: {}
Proj: {}
 planner returned error: unable to find index for $geoNear query

How can I solve this?



from Laravel Questions and Answers https://laravelquestions.com/php/unable-to-find-index-for-geonear-query-while-using-laravel-and-mongodb-using-moloquent/
via Lzo Media

No comments:

Post a Comment