Closed
Description
I am able to search for records using Geospatial query but how to add a where condition for filtering the records in laravel mongodb.
Below is my code to fetch the records without where condition.
$whereObj = ['loc' => ['$near' => ['$geometry' =>
['type' => "Point",'coordinates' => [$data['lng'],$data['lat']]],
'$maxDistance' => 8000]]];
$list = Places::whereRaw($whereObj)->get();
I tried adding a query object in the above $whereObj but i don't get any results when its executed.
Below is the code with where condition to filter data.
$whereObj = ['loc' => ['$near' => ['$geometry' =>
['type' => "Point",'coordinates' => [$data['lng'],$data['lat']]],
'$maxDistance' => 8000]], 'query' => ['status' => 'ACTIVE']];
$list = Places::whereRaw($whereObj)->get();
If I run the below query in mongo shell it works.
db.Places.find(
{
loc : {
$near : {
$geometry : {
type : "Point" ,
coordinates : [77.612865, 12.970787]
},
$maxDistance : 2000
}
},
query : {status : 'ACTIVE'}
}
);
Metadata
Metadata
Assignees
Labels
No labels