在php上显示所有文档
我想展示收藏的所有文件:我制作的这篇文章:在php上显示所有文档,php,mongodb,Php,Mongodb,我想展示收藏的所有文件:我制作的这篇文章: <?php try { $connection = new MongoClient(); $database = $connection->selectDB('Myblog'); $collection = $database->selectCollection('articles'); } catch(Mongo
<?php
try {
$connection = new MongoClient();
$database = $connection->selectDB('Myblog');
$collection = $database->selectCollection('articles');
}
catch(MongoConnectionException $e) {
die("Failed to connect to database ".$e->getMessage());
}
$query=array();
$cursor=$collection->find($query);
foreach ($cursor as $doc) {
echo " Title is : ".$article['title']."";
}
?>
感谢您的帮助遗漏了什么?您仅在从
echo
命令输出的内容中引用标题。如果需要其他字段,则必须引用它们,即($article['content']
等…)使用
foreach ($cursor as $doc) {
echo "Title is : " . $doc['title'];
}
问题是:看起来test,test,test,我想测试1,test2,test3
foreach ($cursor as $doc) {
echo "Title is : " . $doc['title'];
}