1
我试过如下:检索蒙戈集合列在PHP
$mongo = new Mongo("mongodb://localhost");
print_r($mongo);
$db = $mongo->test;
// access collection
$collection = $db->test;
// execute query
// retrieve all documents
print_r($test);
$cursor = $collection->find();
print_r($cursor);
$fields = $cursor->fields(array("summary" => true));
print_r($fields);
输出是:
Mongo Object ([connected] => 1 [status] => [server:protected] => [persistent:protected] =>)
MongoCursor Object ()
MongoCursor Object ()
貌似司机和连接工作,但我不能接受她的列收集test
in db test
。
输出壳客户端的:
> show dbs
local (empty)
test 0.203125GB
> show collections
system.indexes
test
>
> db.test.find()
{ "_id" : ObjectId("51c861eab6a7c3caa2dc51ec"), "name" : "daniel", "randomNumber" : 49 }
{ "_id" : ObjectId("51c861f4b6a7c3caa2dc51ed"), "name" : "peter", "randomNumber" : 31 }
{ "_id" : ObjectId("51c861fab6a7c3caa2dc51ee"), "name" : "ines", "randomNumber" : 7 }
{ "_id" : ObjectId("51c86b19600090465bc233f4"), "name" : "stein", "randomNumber" : 192 }
{ "_id" : ObjectId("51c86b21600090465bc233f5"), "name" : "ziege", "randomNumber" : 42 }
{ "_id" : ObjectId("51c86b36600090465bc233f6"), "name" : "title", "randomNumber" : 753 }
>如何到动态获取列在PHP?
这个作品来获取所有行(适用于'找到()'),我想有没有办法让一个集合中的所有可用不同的领域? – DanFromGermany
看到这个http://stackoverflow.com/questions/5236160/mongo-equivalent-of-sqls-select-distinct – foxtrot
这取得不同的值,但我需要不同的键:-( 像在我上面的示例中,我需要“名称,随机号码“作为结果 – DanFromGermany