I'm using a windows xampp server running PHP 5.4 and the PHP Mongo driver from here.
I am querying the data using:
$results = $collection->find( array('league'=>'nba') );
foreach ($results as $user) {
var_dump($user);
echo "</br>";
}
Result:
array(5) { ["_id"]=> float(3.1677054844223E+18) ["league"]=> string(3) "nba" ["homeTeam"]=> string(10) "Washington" ...
I am converting the ID to a string:
$cursorID = new MongoID($result['_id']);
$gameLink = "<a href='/home/game/".$cursorID."'>".$cursorID."</a>";
which converts the ID from a float to this value: 50fde048f1568a204c0002a1 and trying to query for game details:
$gameID = new MongoID("50fde048f1568a204c0002a1"); //default
$con = new Mongo("mongodb://mongo.example.net"); // Connect to Mongo Server
$db = $con->selectDB('mydb');
$games = $db->games->find( array('_id'=>$gameID) );
But this does not return any results.
Thoughts on what could be going wrong?
objectIds at all for some unknown reason, what does the document look in your database? Can you paste a console output? Your _id may have changed type, if so then you cannot query by objectid