title: Error executing query on MongoDB using PHP
body: <p>I'm trying to execute a simple insert query using PHP as the scripting language.
  However , I am getting the following error instance while executing it.</p>
  
  <pre><code>array(2) { ["ok"]=&gt; float(0) ["errmsg"]=&gt; string(12) "unauthorized" }
  </code></pre>
  
  <p>I wrote the following code on my local machine and it worked fine :</p>
  
  <pre><code>$mongoClient = new MongoClient('localhost');
  $mongoDB=$mongoClient-&gt;test_db;
  $mql='db.products.insert( { item: "card", qty: 15 } );';
  $data=$mongoDB-&gt;execute($mql);
  var_dump($data);die;
  </code></pre>
  
  <p>However , when I run the same code on my dev server using the following code segment while creating the MongoClient object , I am getting the above stated error.</p>
  
  <pre><code>$mongoClient=new MongoClient('mongodb://username:password@dbServer:port/test_db');
  $mongoDB=$mongoClient-&gt;test_db;
  $mql='db.products.insert( { item: "card", qty: 15 } );';
  $data=$mongoDB-&gt;execute($mql);
  var_dump($data);die;
  </code></pre>
  
  <p>On the same DB server , I am able to execute the same query through shell. 
  From the code I can see that I am trying to select the database twice but then I'm left fully confused if that can be the error and how will I eliminate that. 
  If that's not the error , I'm too clueless to find it.</p>
  
  <p>I am using RackSpace cloud servers and ObjectRocket (by Rackspace) for MongoDB instances to be specific but then it should not be anyhow related to the problem. Help me please.</p>