I have this error when I try to use my php file
Fatal error: Cannot use object of type MongoCursor as array in
Part of my code :
<?php
try {
$connection = new MongoClient();
$database = $connection->selectDB('test');
$collection = $database->selectCollection('articles');
} Catch(MongoException $e) {
die("Failed to connect to database ".$e->getMessage());
}
$cursor = $collection->find();
?>
<?php session_start();
?>
<html>
<p> test1 </p>
<p> test </p>
<h3> Comment the photo </h3>
<?php foreach($cursor['comments'] as $comment):
I think error is due to :
- <?php foreach($cursor['comments'] as $comment):
or $cursor = $collection->find();