4

I'm trying to obtain a simple collection doing the next:

<?php
echo "<pre>";
$mongo = new Mongo();
var_dump($mongo);
$db = $mongo->testdb;
var_dump($db);

$cursor = $db->users->find();

var_dump($cursor);
?>

And I get the next output:

object(Mongo)#1 (4) {
  ["connected"]=>
  bool(true)
  ["status"]=>
  NULL
  ["server":protected]=>
  string(0) ""
  ["persistent":protected]=>
  NULL
}
object(MongoDB)#2 (2) {
  ["w"]=>
  int(1)
  ["wtimeout"]=>
  int(10000)
}
object(MongoCursor)#4 (0) {
}

IF in the command line I do this:

use testdb;
db.users.find();

I obtain:

{ "_id" : ObjectId("4e7fca596803fa4b53000000"), "username" : "test4", "password" : "md5pass", "email" : "[email protected]", "group" : 1, "profile_fields" : "a:0:{}" }
{ "_id" : ObjectId("4e7fca6e6803fa4a53000000"), "username" : "test4", "password" : "md5pass", "email" : "[email protected]", "group" : 1, "profile_fields" : "a:0:{}" }
{ "_id" : ObjectId("4e7fca726803fa4a53000001"), "username" : "test4", "password" : "md5pass", "email" : "[email protected]", "group" : 1, "profile_fields" : "a:0:{}" }
{ "_id" : ObjectId("4e7fca736803fa4a53000002"), "username" : "test4", "password" : "md5pass", "email" : "[email protected]", "group" : 1, "profile_fields" : "a:0:{}" }
{ "_id" : ObjectId("4e7fcae26803fa4c53000000"), "username" : "test4", "password" : "md5pass", "email" : "[email protected]", "group" : 1, "profile_fields" : "a:0:{}" }
{ "_id" : ObjectId("4e7fcb076803fa4953000000"), "username" : "test1", "password" : "md5pass", "email" : "[email protected]", "group" : 1, "profile_fields" : "a:0:{}" }

What I'm doing wrong?

Thank you in advance!

1 Answer 1

5

Do a foreach on the Cursor in your first example.

The reason being you do not see anything in the var_dump is that it is a resource. Resources are pointers, they do not hold real data by themselves.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.