2014-11-25 29 views
0

我YiiMongoDbSuite 1.3.6YiiMongoDbSuite + 2dsphere不工作

   $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

呀!!!时看起来很有效。我改变格式的简单查询

 $users = \User::model()->findAll(array (
     "conditions" => array (
      'loc' => array(
       'near' => array(
        '$geometry' => array(
         'type' => 'Point', 
         'coordinates'=> array(-73.951909,40.610876) 
        ) 
       ), 
       'maxDistance' => 1000 
      ) 
     ) 
    ));