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?