0

我有 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}}})

返回有效结果

4

1 回答 1

0

是的!!!似乎它有效。我改变了简单查询的格式

     $users = \User::model ()->findAll(array (
        "conditions" => array (
            'loc' => array(
                'near' => array(
                    '$geometry' => array(
                        'type' => 'Point', 
                        'coordinates'=> array(-73.951909,40.610876)
                    )
                ), 
                'maxDistance' => 1000
            )
        )
    ));
于 2014-11-25T10:28:03.457 回答