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
Post a Comment