I have a database and a table user. when i perform below code i got output as below.
$searchQuery = array('userID' => '2');
$collection = $db->mydatabase->users;
$cursor = $collection->find()->limit(2);
foreach ($cursor as $doc) {
var_dump($doc);
}
Output:
array(4) {
'_id' =>
class MongoId#8 (1) {
public $$id =>
string(24) "56c8216d7f8b9a0e148b4567"
}
'userID' =>
int(7)
'lastTimeOnline' =>
string(19) "2016-02-20 01:48:53"
'displayName' =>
string(0) ""
}
array(4) {
'_id' =>
class MongoId#9 (1) {
public $$id =>
string(24) "56c8216d7f8b9a0e148b4568"
}
'userID' =>
int(2)
'lastTimeOnline' =>
string(19) "2016-02-20 01:48:53"
'displayName' =>
string(0) ""
}
Now i need to find only those records whose userID is 2, so i change the code as below.
$searchQuery = array('userID' => '2');
$collection = $db->mydatabase->users;
$cursor = $collection->find($searchQuery)->limit(2);
foreach ($cursor as $doc) {
var_dump($doc);
}
but now the output is blank :-(
I have two doubts. A) why 2nd code to fetch userId=2 is not working B)why on both cases var_dump($cursor) is giving below output and why not detail of $doc
class MongoCursor#5 (0) {
}