mysql_xdevapi\Collection
PHP Manual

Collection::find

(No version information available, might only be in Git)

Collection::findSearch for document

说明

public mysql_xdevapi\CollectionFind mysql_xdevapi\Collection::find ([ string $search_condition ] )

Search a database collection for a document or set of documents. The returned documents are contained in the CollectionFind object that can be used further to fetch one or all the documents.

参数

search_condition

Although optional, normally a condition is defined to limit the results to a subset of documents.

Multiple elements might build the condition and the syntax supports parameter binding. The expression used as search condition must be a valid SQL expression. If no search condition is provided (field empty) then find('true') is assumed.

返回值

A CollectionFind object that can use used to verify the operation or fetch found documents.

范例

Example #1 mysql_xdevapi\Collection::find() example

<?php

// Assuming $coll is a valid Collection object

$coll->add('{"name": "Marco",      "age": 19, "job": "Programmatore"}')->execute();
$coll->add('{"name": "Lonardo",    "age": 59, "job": "Paninaro"}')->execute();
$coll->add('{"name": "Riccardo",   "age": 27, "job": "Cantante"}')->execute();
$coll->add('{"name": "Carlotta",   "age": 23, "job": "Programmatrice"}')->execute();
$coll->add('{"name": "Carlo",      "age": 25, "job": "Programmatore"}')->execute();
$coll->add('{"name": "Mariangela", "age": 41, "job": "Programmatrice"}')->execute();
$coll->add('{"name": "Alfredo",    "age": 27, "job": "Programmatore"}')->execute();
$coll->add('{"name": "Antonella",  "age": 42, "job": "Studente"}')->execute();
$coll->add('{"name": "Monica",     "age": 35, "job": "Ballerino"}')->execute();
$coll->add('{"name": "Giulio",     "age": 29, "job": "Disoccupato"}')->execute();
$coll->add('{"name": "Lucia",      "age": 47, "job": "Barista"}')->execute();
$coll->add('{"name": "Filippo",    "age": 31, "job": "Spazzino"}')->execute();
$coll->add('{"name": "Alessandra", "age": 15, "job": "Barista"}')->execute();
$coll->add('{"name": "Massimo",    "age": 22, "job": "Programmatore"}')->execute();
$coll->add('{"name": "Carlo",      "age": 37, "job": "Calciatore"}')->execute();

/*
   This query will look for up to 2 documents in the Collection sorted by age (descending),
   the documents must have the job 'Programmatore' and the age field higher or equal to 20

   The actual resulting documents are 'Carlo' and 'Alfredo'
*/

$obj  $coll->find('job like :job and age > :age')->fields('age');
$res  $obj->bind(['job' => 'Programmatore''age' => 20])->sort('age desc')->limit(2);
$data $res->execute()->fetchAll();

// The search condition mighe also be very complex and use multiple functions
$res  $coll->find('(1>5) IN (true,false) && {"title":"Spavatore"} NOT IN jobs && CAST(_id AS SIGNED) > 2')->execute();

?>

mysql_xdevapi\Collection
PHP Manual