I am using Laravel 5 with mongo Db database. I have used jenssegers/laravel-mongodb package for all mongo related functions. Everything is working fine.
But when i tried geonear as per information provide on this link([Geo near query link][1]) of mongodb. I works fine. I used following query to get distance between all records of my collection.
Command:-
({ geoNear: "sale_event",
near: {
type: "Point",
coordinates: [ 76.7171945,30.7291196 ]
},
spherical: true,
})
this query is working fine in command prompt and giving me the distance with result :-
{
"results" : [
{
"dis" : 0,
"obj" : {
"_id" : ObjectId("568e01fc04896fcd208b4575"),
"seller_rating" : "4.5",
"latLong" : [
76.7171945,
30.7291196
],
"description" : "Where'd",
"updated_at" : ISODate("2016-01-07T06:13:16.152Z"),
"created_at" : ISODate("2016-01-07T06:13:16.150Z")
}
},
{
"dis" : 244708.75191385587,
"obj" : {
"_id" : ObjectId("568e01eb04896fcd208b4574"),
"seller_rating" : "4.5",
"latLong" : [
77.0999578,
28.5561624
],
"description" : "Where'd",
"updated_at" : ISODate("2016-01-07T06:12:59.263Z"),
"created_at" : ISODate("2016-01-07T06:12:59.261Z")
}
}
],
"stats" : {
"nscanned" : 20,
"objectsLoaded" : 2,
"avgDistance" : 122354.37595692794,
"maxDistance" : 244708.75191385587,
"time" : 3
},
"ok" : 1
}
But when i used same command in laravel it is not giving me the same result :-
I have added following method to run the same command.
$r = DB::command(array( 'geoNear' => "sale_events",
'near' => array( 'type' => "Point", 'coordinates' => array('76.7171945','30.7291196')), 'spherical' => true ));
It giving me following result :-
Array
(
[ok] => 0
[errmsg] => can't find ns
)
Please help me how can i get the distance in laravel according to the latitude and longitude with mongodb in laravel.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire