mongo_connect
mongo_gridchunk_data
Mongo Функции
PHP Manual

# mongo_find_one

(PECL mongo >= 0.8.0)

mongo_find_one — Queries the database for a single record

### Описание

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.

### Список параметров

`connection`

  The database connection to use.

`ns`

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

`query`

  An array representing the desired results.

### Возвращаемые значения

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

### Примеры

Пример #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()));
?>`

Результатом выполнения данного примера будет что-то подобное:

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

Пример #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)));
?>`

Результатом выполнения данного примера будет что-то подобное:

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

mongo_connect
mongo_gridchunk_data
Mongo Функции
PHP Manual