title: Fatal error: Cannot use object of type MongoCursor as array
body: <p>I'm using MongoDB with php - I'm trying to get the id of the user who has logged in with a username &amp; password and store it as a session variable.</p>
  
  <p>I keep getting this error and I don't understand why.</p>
  
  <pre><code>&lt;?php
  session_start();
  
  $dbhost = 'localhost';
  $dbname = 'story';
  
  $mongo = new MongoClient("mongodb://$dbhost");
  $db = $mongo-&gt;$dbname;
  
  $collection = $db-&gt;users;
  
  $email=$_POST['email'];
  $password=$_POST['password'];
  
  $user = $collection-&gt;find(array("email" =&gt; $email, "password" =&gt; $password));
  $user-&gt;limit(1);
  if ($user-&gt;count(true) &gt; 0){
      $_SESSION['user']['userid']=iterator_to_array($user['_id']-&gt;{'$id'});
      header("Location:../webpages/master.php?page=home");
  }else{
      echo "Wrong username or password";
  }
  </code></pre>
  
  <p>?></p>