I do this way:
$cursorLocations = $collection->find( array("locationName" => $locationName) )->limit(1);
if ($cursorLocations->count(true) == 1) {
$idLocations = $cursorLocations->getNext();
echo $idLocations["_id"];
}
I immediately apologize if this question has been, but read the documentation did not find an answer.
Maybe some other way to get the _id?
in Mongo :
in PHP:
The above code will limit your query to retrieving only the
_idfield and not the other fields, you would still have to extract the value of that field from the result of thefind()function – from the$cursorobject, like in:There is also a MongoCursor method
key()which returns the current_id:http://www.php.net/manual/en/mongocursor.key.php
So you could do this: