update : 2015.11.03
php.shukuma.com

검색:
 
 
Construct new Query

MongoDB\Driver\Query::__construct

(mongodb >=0.2.0)

MongoDB\Driver\Query::__constructConstruct new Query

설명

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

인수

filter (array|object)

The search filter.

queryOptions

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)

오류/예외

  • Throws MongoDB\Driver\InvalidArgumentException on argument parsing errors.

예제

Example #1 MongoDB\Driver\Query::__construct() example

<?php
$filter 
= 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);

foreach(
$cursor as $document) {
    
var_dump($document);
}

?>