Mongo Funktionen
PHP Manual

mongo_find_one

(PECL mongo >= 0.8.0)

mongo_find_oneQueries the database for a single record

Beschreibung

array mongo_find_one ( resource $connection , string $ns , array $query )

Queries the database for a single record. This can also be used for database commands.

Parameter-Liste

connection

The database connection to use.

ns

A string of the form [database_name].[collection_name].

query

An array representing the desired results.

Rückgabewerte

Returns an array if an element matching the query was found, null otherwise.

Beispiele

Beispiel #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()));

?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

array(2) {
  ["_id"]=>
  object(MongoId)#1 (1) {
    ["id"]=>
    string(24) "49a2e6f55b8b4a17e843cf3d"
  }
  ["x"]=>
  string(1) "y"
}

Beispiel #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)));

?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

array(7) {
  ["dbasserted"]=>
  bool(false)
  ["asserted"]=>
  bool(false)
  ["assert"]=>
  string(0) ""
  ["assertw"]=>
  string(0) ""
  ["assertmsg"]=>
  string(0) ""
  ["assertuser"]=>
  string(0) ""
  ["ok"]=>
  float(1)
}


Mongo Funktionen
PHP Manual