如何用mongodb / PHP7上的子句查询?

时间:2019-01-10 10:59:59

标签: php mongodb

这是我与mongodb的第一次接触,我正在用MONGODB数据库编写PHP7,不知道如何查询。

我的查询适用于mongo:

db.points.find( 
    { coordenadas: 
        { $geoWithin: 
            { $centerSphere: 
                [ [ -23.010382,-43.476006 ] , 10 / 3963.2 ] 
             } 
         } 
    }
)

但是我不知道如何在PHP上编码: ...

try {
    $mongo = new MongoDB\Driver\Manager('mongodb://localhost:27017');
    $filter = [

问题在这里! 如何编写MONGO的发现

    ];
$query = new MongoDB\Driver\Query($filter);
$rows = $mongo->executeQuery(“points”, $query);

...

1 个答案:

答案 0 :(得分:0)

上述查询的PHP代码如下:

$condition = array(
                'coordenadas' => array(
                    '$geoWithin' => array(
                        '$centerSphere' =>  
                           array(array( -23.010382,-43.476006 ), 10 / 3963.2)
                    )
                )
             );

如果您的数据库名称为“ my_db ”,而集合名称为“ point_collection

$collection = $mongo->my_db->point_collection;
$result = $collection->find($query);

您可以参考find()的文档;