(mongodb >=1.0.0)

MongoDB\Driver\Query::__constructConstruct new Query


final public MongoDB\Driver\Query::__construct ( array|object $filter [, array $queryOptions ] )


filter (array|object)

The search filter.


Option Type Description
limit integer The number of documents to be returned
batchSize integer The number of documents to return per batch
skip integer The number of documents to skip before returning
sort array|object The order in which to return matching documents
modifiers array Meta operators modifying the output or behavior of a query
projection array|object Specifies the fields to return using booleans or projection operators
tailable bool Cursor will not be closed when the last data is retrieved. You can resume this cursor later
slaveOk bool Allow query of replica set secondaries
oplogReplay bool Internal MongoDB Server flag
noCursorTimeout bool Do not timeout a cursor that has been idle for more then 10minutes
awaitData bool Block rather than returning no data. After a period, time out. Useful for tailable cursor
exhaust bool Stream the data down full blast in multiple "reply" packets. Faster when you are pulling down a lot of data and you know you want to retrieve it all
partial bool Get partial results from mongos if some shards are down (instead of throwing an error)



Приклад #1 MongoDB\Driver\Query::__construct() example

= array();
$options = array(
/* Only return the following fields in the matching documents */
"projection" => array(
"title" => 1,
"article" => 1,
"sort" => array(
"views" => -1,
"modifiers" => array(
'$comment'   => "This is a query comment",
'$maxTimeMS' => 100,

$query = new MongoDB\Driver\Query($filter$options);

$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$readPreference = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY);
$cursor $manager->executeQuery("databaseName.collectionName"$query$readPreference);

$cursor as $document) {


Прогляньте Також

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top