public function testUnacknowledgedWriteConcern()
 {
     $ops = [['insertOne' => [['_id' => 1]]]];
     $options = ['writeConcern' => new WriteConcern(0)];
     $operation = new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), $ops, $options);
     $result = $operation->execute($this->getPrimaryServer());
     $this->assertFalse($result->isAcknowledged());
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Executes multiple write operations.
  *
  * @see BulkWrite::__construct() for supported options
  * @param array[] $operations List of write operations
  * @param array   $options    Command options
  * @return BulkWriteResult
  */
 public function bulkWrite(array $operations, array $options = [])
 {
     if (!isset($options['writeConcern'])) {
         $options['writeConcern'] = $this->writeConcern;
     }
     $operation = new BulkWrite($this->databaseName, $this->collectionName, $operations, $options);
     $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
     return $operation->execute($server);
 }
 /**
  * Executes a data modification from an "arrange" or "assert" block.
  *
  * @param array $dataModification
  * @return mixed
  * @throws LogicException if the operation or collection is unsupported
  */
 private function executeDataModification(array $dataModification)
 {
     foreach ($dataModification as $type => $collectionName) {
         break;
     }
     if (!in_array($collectionName, ['fs.files', 'fs.chunks', 'expected.files', 'expected.chunks'])) {
         throw new LogicException('Unsupported collection: ' . $collectionName);
     }
     $dataModification = $this->convertTypes($dataModification);
     $operations = [];
     switch ($type) {
         case 'delete':
             foreach ($dataModification['deletes'] as $delete) {
                 $operations[] = [$delete['limit'] === 1 ? 'deleteOne' : 'deleteMany' => [$delete['q']]];
             }
             break;
         case 'insert':
             foreach ($dataModification['documents'] as $document) {
                 $operations[] = ['insertOne' => [$document]];
             }
             break;
         case 'update':
             foreach ($dataModification['updates'] as $update) {
                 $operations[] = ['updateOne' => [$update['q'], $update['u']]];
             }
             break;
         default:
             throw new LogicException('Unsupported arrangement: ' . $type);
     }
     $bulk = new BulkWrite($this->getDatabaseName(), $collectionName, $operations);
     return $bulk->execute($this->getPrimaryServer());
 }