我有collection
名称restaurant
,它有120万条记录。我想根据我的地理位置(即纬度/长度)找到距离1英里半径近的餐厅
示例:在这里,我分享了120万restaurant
集合中的2个文档:
{
"_id" : ObjectId("5937aa44ae5fbf080d017fdc"),
"factual_id" : "d37774d0-e379-4325-83ed-6fee2f6820f6",
"name" : "Orange Deli Grocery",
"address" : "145 Avenue D",
"address_extended" : null,
"po_box" : null,
"locality" : "New York",
"region" : "NY",
"post_town" : null,
"admin_region" : null,
"postcode" : NumberInt("10009"),
"country" : "us",
"tel" : "(212) 228-2710",
"fax" : null,
"latitude" : 40.724909,
"longitude" : -73.97533,
"loc" : {
"type" : "Point",
"coordinates" : [
-73.97533,
40.724909
]
}
},
/* 2 createdAt:6/7/2017, 1:06:53 PM*/
{
"_id" : ObjectId("5937ad15ae5fbf8003000ff9"),
"factual_id" : "18393fb5-6061-4281-84f5-d860d78e88a0",
"name" : "El Rinconcito",
"address" : "408 E 10th St",
"address_extended" : "Frnt 2",
"po_box" : null,
"locality" : "New York",
"region" : "NY",
"post_town" : null,
"admin_region" : null,
"postcode" : NumberInt("10009"),
"country" : "us",
"tel" : "(212) 254-1381",
"fax" : "(646) 590-3673",
"latitude" : 40.725591,
"longitude" : -73.976997,
"loc" : {
"type" : "Point",
"coordinates" : [
-73.976997,
40.725591
]
}
}
现在,当我在mongo shell中运行以下查询时,我得到5000条记录。
var query = {
"loc" : {
$geoWithin : {
$centerSphere : [[-73.993068,40.722355], 1/3959 ]
}
}
};
// Step 2: Query points.
db.restaurant.find(query)
但是当我尝试使用PHP
同样的事情时,我会得到空的回复
$args = array(
'loc' => array(
"\$geoWithin" => array(
"\$centerSphere" => array(
array(-73.993068,40.722355), 1/3959
)
)
)
);
// here i have successfully connection with mongo
$collection = new MongoCollection($this->mongo_db->db, 'restaurant');
$cursor = $collection->find($args);
foreach ($cursor as $doc) {
var_dump($doc);
}