March 2019
Intermediate to advanced
394 pages
11h 4m
English
Querying an interface is similar to inserting and deleting, with the findOne() and find() methods used to retrieve the first result or all results of a query:
$document = $collection->findOne( array("isbn" => "401") );$cursor = $collection->find( array( "name" => new MongoDB\BSON\Regex("mongo", "i") ) );
In the second example, we are using a regular expression to search for a key name with the value, mongo (which is case insensitive).
Embedded documents can be queried using the . notation, as with the other languages that we examined earlier in this chapter:
$cursor = $collection->find( array('meta.price' => 50) );
We do this to query for a price embedded document inside the meta key field.
Similarly to Ruby and Python, in PHP, we can ...
Read now
Unlock full access