Database Reference
In-Depth Information
The result returned looks like this:
Array (
[value] => Array (
[Given Name] => Kenji
[Family Name] => Kitahara
[Address] => Array (
[Street] => 149 Bartlett Avenue
[Place] => Southfield
[Postal Code] => MI 48075
[Country] => USA
)
[E-Mail] => Array (
[0] =>
kk@example.com
[1] =>
kk@office.com
)
[Phone] => 248-510-1562
[Age] => 34
[_id] => MongoId Object ( )
[Category] => Work
)
[ok] => 1
)
The following example shows how to use the
remove
and
sort
parameters:
// Connect to the database
$c = new MongoClient();
// Specify the database and collection in which to work
$collection = $c->contacts->people;
// Specify the search criteria
$criteria = array("Category" => "Work");
// Specify the options
$options = array("sort" => array("Age" => -1), "remove" => true);
// Perform a findAndModify()
$collection->findAndModify($criteria,null,null,$options);
Deleting Data
You can use the
remove()
function to remove a document like the one in the preceding example from the MongoDB
shell. The PHP driver also includes a
remove()
function you can use to remove data. The PHP version of this function
takes two parameters: one contains the description of the record or records to remove, while the other specifies
additional options governing the removal process.
There are seven options available:
•
justOne
: If set to true, at most only one record matching the criteria must be removed.
•
fsync
: If set to
true
, this Boolean option causes the data to be synced to disk before returning
a success. If this option is set to
true
, then it's implied that
w
is set to
0
, even if it's set
otherwise.