(No version information available, might only be in Git)
Collection::getOne — Get one document
$id
)
This is a shortcut for Collection.find("_id = :id").bind("id", id).execute().fetchOne();
.
id
The document ID in the collection.
The collection object, or NULL
if the ID does not match a document.
Example #1 mysql_xdevapi\Collection::getOne() example
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@host");
$schema = $session->getSchema('test');
$coll = $schema->getCollection('test_collection');
$coll->add('{"_id": "1", "name": "Marco", "age": 19, "job": "Programmatore"}')->execute();
$coll->add('{"_id": "2", "name": "Lonardo", "age": 59, "job": "Paninaro"}')->execute();
$coll->add('{"_id": "3", "name": "Riccardo", "age": 27, "job": "Cantante"}')->execute();
$coll->add('{"_id": "4", "name": "Carlotta", "age": 23, "job": "Programmatrice"}')->execute();
$coll->add('{"_id": "5", "name": "Carlo", "age": 25, "job": "Programmatore"}')->execute();
print_r( $coll->getOne(3) );
print_r( $coll->getOne(5) );
?>
以上例程的输出类似于:
Array ( [_id] => 3 [age] => 27 [job] => Cantante [name] => Riccardo ) Array ( [_id] => 5 [age] => 25 [job] => Programmatore [name] => Carlo )