更新时间:2023-11-17 08:23:58
If you are using latest MongoDB extension of PHP, MongoDB\Driver\Manager
is the main entry point to the extension.
这是使用最新扩展名检索数据的示例代码.
Here is the sample code to retrieve data using latest extension.
假设您在testDb
中具有testColl
集合.您可以使用扩展的 MongoDB\Driver\Query
类检索数据
Let's say you have testColl
collection in testDb
. The you can retrieve data using MongoDB\Driver\Query
class of the extension.
// Manager Class
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
// Query Class
$query = new MongoDB\Driver\Query(array('age' => 30));
// Output of the executeQuery will be object of MongoDB\Driver\Cursor class
$cursor = $manager->executeQuery('testDb.testColl', $query);
// Convert cursor to Array and print result
print_r($cursor->toArray());
输出:
Array
(
[0] => stdClass Object
(
[_id] => MongoDB\BSON\ObjectID Object
(
[oid] => 5848f1394cea9483b430d5d2
)
[name] => XXXX
[age] => 30
)
)