MongoDB PHP驱动程序函数的名称与shell对应函数的名称类似,因此在本例中,您将使用
MongoCollection::find()
. PHP驱动程序使用关联数组将字段映射到MongoDB查询。
MongoCollection::find()
文档页面目前没有包含投影的示例,为了完整起见,我在下面添加了一个示例:
<?php
$m = new MongoClient();
$db = $m->selectDB('test');
$collection = new MongoCollection($db, 'SoManySins');
// Search criteria
$query = array();
// Projection (fields to include)
$projection = array("_id" => false, "FactoryCapacity" => true);
$cursor = $collection->find($query, $projection);
foreach ($cursor as $doc) {
var_dump($doc);
}
?>
对于投影等级库,可以使用1/0(包括/排除),如
mongo
shell或等效的真/假常量。
这很值得通过
Tutorial
在PHP MongoDB驱动程序文档中以及查看
archived presentations