(PECL mongo >= 0.8.0)
mongo_find_one — Queries the database for a single record
Queries the database for a single record. This can also be used for database commands.
The database connection to use.
A string of the form [database_name].[collection_name].
An array representing the desired results.
Returns an array if an element matching the query was found, null otherwise.
Example #1 mongo_find_one() example
This example shows how to find the most recently inserted record in the collection "bar" in the database "foo".
<?php
$conn = mongo_connect("localhost", true);
if (!$conn) {
die("Could not connect.");
}
mongo_insert($conn, "foo.bar", array( "x" => "y" ));
var_dump(mongo_find_one($conn, "foo.bar", array()));
?>
The above example will output something similar to:
array(2) { ["_id"]=> object(MongoId)#1 (1) { ["id"]=> string(24) "49a2e6f55b8b4a17e843cf3d" } ["x"]=> string(1) "y" }
Example #2 mongo_find_one() example
This example shows how to execute a database command using the "foo" database.
<?php
$conn = mongo_connect("localhost", true);
if (!$conn) {
die("Could not connect.");
}
var_dump(mongo_find_one($conn, 'foo.$cmd', array('assertinfo' => 1)));
?>
The above example will output something similar to:
array(7) { ["dbasserted"]=> bool(false) ["asserted"]=> bool(false) ["assert"]=> string(0) "" ["assertw"]=> string(0) "" ["assertmsg"]=> string(0) "" ["assertuser"]=> string(0) "" ["ok"]=> float(1) }