©
本文档使用 PHP中文网手册 发布
(mongodb >=1.0.0)
MongoDB\Driver\Query::__construct — Construct new Query
$filter
[, array $queryOptions
] )
filter
( array|object )The search filter.
queryOptions
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) |
Example #1 MongoDB\Driver\Query::__construct() example
<?php
$filter = array();
$options = array(
"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 );
foreach( $cursor as $document ) {
var_dump ( $document );
}
?>