Ejemplo n.º 1
0
 /**
  * Create the aggregate command.
  *
  * @param Server  $server
  * @param boolean $isCursorSupported
  * @return Command
  */
 private function createCommand(Server $server, $isCursorSupported)
 {
     $cmd = ['aggregate' => $this->collectionName, 'pipeline' => $this->pipeline];
     // Servers < 2.6 do not support any command options
     if (!$isCursorSupported) {
         return new Command($cmd);
     }
     $cmd['allowDiskUse'] = $this->options['allowDiskUse'];
     if (isset($this->options['bypassDocumentValidation']) && \MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)) {
         $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
     }
     if (isset($this->options['maxTimeMS'])) {
         $cmd['maxTimeMS'] = $this->options['maxTimeMS'];
     }
     if (isset($this->options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) {
         $cmd['readConcern'] = \MongoDB\read_concern_as_document($this->options['readConcern']);
     }
     if ($this->options['useCursor']) {
         $cmd['cursor'] = isset($this->options["batchSize"]) ? ['batchSize' => $this->options["batchSize"]] : new stdClass();
     }
     return new Command($cmd);
 }
Ejemplo n.º 2
0
 /**
  * Create the count command.
  *
  * @param Server $server
  * @return Command
  */
 private function createCommand(Server $server)
 {
     $cmd = ['count' => $this->collectionName];
     if (!empty($this->filter)) {
         $cmd['query'] = (object) $this->filter;
     }
     foreach (['hint', 'limit', 'maxTimeMS', 'skip'] as $option) {
         if (isset($this->options[$option])) {
             $cmd[$option] = $this->options[$option];
         }
     }
     if (isset($this->options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) {
         $cmd['readConcern'] = \MongoDB\read_concern_as_document($this->options['readConcern']);
     }
     return new Command($cmd);
 }
Ejemplo n.º 3
0
 /**
  * @dataProvider provideReadConcernsAndDocuments
  */
 public function testReadConcernAsDocument(ReadConcern $readConcern, $expectedDocument)
 {
     $this->assertEquals($expectedDocument, \MongoDB\read_concern_as_document($readConcern));
 }
Ejemplo n.º 4
0
 /**
  * Create the distinct command.
  *
  * @param Server $server
  * @return Command
  */
 private function createCommand(Server $server)
 {
     $cmd = ['distinct' => $this->collectionName, 'key' => $this->fieldName];
     if (!empty($this->filter)) {
         $cmd['query'] = (object) $this->filter;
     }
     if (isset($this->options['maxTimeMS'])) {
         $cmd['maxTimeMS'] = $this->options['maxTimeMS'];
     }
     if (isset($this->options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) {
         $cmd['readConcern'] = \MongoDB\read_concern_as_document($this->options['readConcern']);
     }
     return new Command($cmd);
 }