我正在尝试获取下一个简单的集合:
<?php
echo "<pre>";
$mongo = new Mongo();
var_dump($mongo);
$db = $mongo->testdb;
var_dump($db);
$cursor = $db->users->find();
var_dump($cursor);
?>
Run Code Online (Sandbox Code Playgroud)
我得到了下一个输出:
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) {
}
Run Code Online (Sandbox Code Playgroud)
如果在命令行中我执行此操作:
use testdb;
db.users.find();
Run Code Online (Sandbox Code Playgroud)
我获得:
{ "_id" : ObjectId("4e7fca596803fa4b53000000"), "username" : "test4", "password" : "md5pass", "email" : "test4@email.tld", "group" : 1, "profile_fields" : "a:0:{}" }
{ "_id" : ObjectId("4e7fca6e6803fa4a53000000"), "username" : "test4", "password" : "md5pass", "email" : "test4@email.tld", "group" : 1, "profile_fields" : "a:0:{}" }
{ "_id" : ObjectId("4e7fca726803fa4a53000001"), "username" : "test4", "password" : "md5pass", "email" : "test4@email.tld", "group" : 1, "profile_fields" : "a:0:{}" }
{ "_id" : ObjectId("4e7fca736803fa4a53000002"), "username" : "test4", "password" : "md5pass", "email" : "test4@email.tld", "group" : 1, "profile_fields" : "a:0:{}" }
{ "_id" : ObjectId("4e7fcae26803fa4c53000000"), "username" : "test4", "password" : "md5pass", "email" : "test4@email.tld", "group" : 1, "profile_fields" : "a:0:{}" }
{ "_id" : ObjectId("4e7fcb076803fa4953000000"), "username" : "test1", "password" : "md5pass", "email" : "test1@email.tld", "group" : 1, "profile_fields" : "a:0:{}" }
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
先感谢您!