如何使用PHP获取整个MongoDB集合

如何使用PHP获取整个MongoDB集合,php,mongodb,Php,Mongodb,使用以下代码,我可以从集合中获取节点: <?php $user = "xxxx"; $pwd = 'xxxx'; if (isset($_POST['needleID'])) { $needleID = $_POST['needleID']; } else { echo "needle ID not set"; } //Manager Class $connection = new MongoDB\Driver\Manager("mongodb://${user}:$

使用以下代码,我可以从集合中获取节点:

<?php

$user = "xxxx";
$pwd = 'xxxx';

if (isset($_POST['needleID'])) {
    $needleID = $_POST['needleID'];
} else {
    echo "needle ID not set";
}

//Manager Class
$connection = new MongoDB\Driver\Manager("mongodb://${user}:${pwd}@localhost:27017");

// Query Class
$filter = ['id'=> $needleID];
$query = new MongoDB\Driver\Query($filter);

// Output of the executeQuery will be object of MongoDB\Driver\Cursor class
$rows = $connection->executeQuery('DBNAME.DBCOLLECTION', $query);

// Convert rows to Array and send result back to javascript as json
$rowsArr = $rows->toArray();
echo json_encode($rowsArr);

?>

然而,我真正想要做的是从DBCOLLECTION中获取所有内容


我不知道该怎么做。一些搜索要么在我的头上搜索,要么在搜索PHP驱动程序的旧版本,比如这一个

如果您查询特定ID,那么您将只收到该ID作为其值的文档。如果要检索集合中的所有文档,请将筛选器保留为空,即使用
$filter=[]

最好用于导出集合。在大型集合上,您的代码将很慢并且会超时。考虑对结果使用分页。

i rdUm。哈。谢谢,这很有道理!没问题。在这里,我强烈建议您考虑使用MUGDB的用户字段库。这不是必须的,但它包装了驱动程序的功能,使查询变得更简单。它需要多大才能成为问题?我认为最大的一次收集大约相当于1500行文字。