Almost everything that is not a CRUD operation can be done with a database
command. Need to know the database version? There's a command for that.
Need to do aggregation? There's a command for that. Need to turn up
logging? You get the idea.
This method is identical to:
<?php
public function command($data) { return $this->selectCollection('$cmd')->findOne($data); }
?>
인수
command
The query to send.
options
An array of options for the index creation. Currently available options
include:
"socketTimeoutMS"
This option specifies the time limit, in milliseconds, for socket communication. If the server does not respond within the timeout period, a MongoCursorTimeoutException will be thrown and there will be no way to determine if the server actually handled the write or not. A value of -1 may be specified to block indefinitely. The default value for MongoClient is 30000 (30 seconds).
The following options are deprecated and should no longer be used:
Renamed the "timeout" option to
"socketTimeoutMS". Emits
E_DEPRECATED when "timeout" is
used.
Added hash by-reference parameter.
1.2.0
Added options parameter with a single option:
"timeout".
반환값
Returns database response. Every database response is always maximum one
document, which means that the result of a database command can never
exceed 16MB. The resulting document's structure depends on the command, but
most results will have the ok field to indicate success
or failure and results containing an array of each of
the resulting documents.
This example uses MongoCode, which can also take a
scope argument. However, at the moment, MongoDB does not support using
scopes in MapReduce. If you would like to use client-side variables in the
MapReduce functions, you can add them to the global scope by using the
optional scope field with the database command. See the
» MapReduce documentation
for more information.
Note:
The out argument
Before 1.8.0, the out argument was optional. If you did
not use it, MapReduce results would be written to a temporary collection,
which would be deleted when your connection was closed. In 1.8.0+, the
out argument is required. See the
» MapReduce documentation
for more information.
Example #4 MongoDB::command() "geoNear" example
This example shows how to use the geoNear command.