我有YiiMongoDbSuite 1.3.6
$users = MyModel::model()->findAll(array(
'conditions'=>array(
'loc'=>array(
'near' => array(50,50),
'maxDistance' => 1 / 111.12,
),
),
));
添加到EMongoCriteria.php附加标准
public static $operators = array(
....
'near' => '$near',
'maxdistance' => '$maxDistance');
返回
之类的消息{
"message": "localhost:27017: can't parse query (2dsphere): { $near: [ -73.951909, 40.610876 ], $maxDistance: 8.999280057595392 }",
"file": "/home/yura/www/doctor/protected/extensions/YiiMongoDbSuite/EMongoDocument.php",
"line": 1232
}
也将字段编入索引
{
"v" : 1,
"name" : "2dsphere",
"key" : {
"loc" : "2dsphere"
},
"ns" : "doctor.users"
}
请求时在控制台中
db.users.find({loc:{$near:{$geometry: {type:"Point", coordinates: [-73.951909, 40.610876]}, $maxDistance: 1000}}})
返回有效结果
答案 0 :(得分:0)
呀!似乎有效。我在
上更改了简单查询的格式 $users = \User::model ()->findAll(array (
"conditions" => array (
'loc' => array(
'near' => array(
'$geometry' => array(
'type' => 'Point',
'coordinates'=> array(-73.951909,40.610876)
)
),
'maxDistance' => 1000
)
)
));