我有 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}}})
返回有效结果