How to get all _ids from MongoDB collection in PHP? -


i want _ids mongodb collection using php. possible?

yes, is:

$connection = new mongoclient(); $collection = $connection->database->collectionname;  $cursor = $collection->find(); foreach ( $cursor $id => $value ) {     var_dump($value['_id']); //object(mongoid) } 

you can read more mongoid object here

from comments:

if need actual id string, , try usual way, php whine because starts dollar sign , thinks it's variable. instead, use notation:

$mongoid->{'$id'} //get $id property of mongoid object 

Comments

Popular posts from this blog

php - Passing multiple values in a url using checkbox -

compilation - PHP install fails on Ubuntu 14 (make: *** [sapi/cli/php] Error 1) PHP 5.6.20 -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -