/** * {@inheritdoc} */ public function clear($key = null) { if (!$key) { $this->collection->drop(); return true; } if ($this->collection instanceof \MongoDB\Collection) { $this->collection->deleteMany(['_id' => new \MongoDB\BSON\Regex("^" . preg_quote(self::mapKey($key)), '')]); } else { $this->collection->remove(['_id' => new \MongoRegex("^" . preg_quote(self::mapKey($key)))], ['multiple' => true]); } return true; }
/** * {@inheritdoc} */ public function clear() { try { $this->collection->drop(); } catch (Exception $e) { throw WriteException::forException($e); } }
/** * Drop the collection if it exists. * * @param Collection $collection */ protected function dropCollectionIfItExists(Collection $collection) { $database = new Database($this->manager, $collection->getDatabaseName()); $collections = $database->listCollections(array('filter' => array('name' => $collection->getCollectionName()))); if (iterator_count($collections) > 0) { $this->assertCommandSucceeded($collection->drop()); } }
public function tearDown() { foreach (['fs.files', 'fs.chunks'] as $collection) { $col = new Collection($this->manager, $this->getDatabaseName(), $collection); $col->drop(); } if ($this->hasFailed()) { return; } }
/** * Replace a document * @param $filter * @param $replacement * @param array $options * @return \MongoDB\UpdateResult */ public function remove($filter = "*", array $options = [], $multiple = false) { if ($filter == "*") { return parent::drop(); } else { if ($multiple === true) { return parent::deleteMany($filter, $options); } else { return parent::deleteOne($filter, $options); } } }
/** * Drops this collection * * @link http://www.php.net/manual/en/mongocollection.drop.php * @return array Returns the database response. */ public function drop() { return TypeConverter::toLegacy($this->collection->drop()); }
public function dropCollection() { $this->_collection->drop(); }
/** * Drops this collection * @link http://www.php.net/manual/en/mongocollection.drop.php * @return array Returns the database response. */ public function drop() { return $this->collection->drop(); }
public function initializeDatabases($data, $test) { $collectionsToDrop = ['fs.files', 'fs.chunks', 'expected.files', 'expected.chunks']; $data = $this->fixTypes($data, true); foreach ($collectionsToDrop as $collectionName) { $collection = new Collection($this->manager, sprintf("%s.%s", $this->getDatabaseName(), $collectionName)); $collection->drop(); } if (isset($data['files']) && count($data['files']) > 0) { $filesCollection = new Collection($this->manager, sprintf("%s.%s", $this->getDatabaseName(), "fs.files")); $filesCollection->insertMany($data['files']); $expectedFilesCollection = new Collection($this->manager, sprintf("%s.%s", $this->getDatabaseName(), "expected.files")); $expectedFilesCollection->insertMany($data['files']); $this->collections['expected.files'] = $expectedFilesCollection; } if (isset($data['chunks']) && count($data['chunks']) > 0) { $chunksCollection = new Collection($this->manager, sprintf("%s.%s", $this->getDatabaseName(), "fs.chunks")); $chunksCollection->insertMany($data['chunks']); $expectedChunksCollection = new Collection($this->manager, sprintf("%s.%s", $this->getDatabaseName(), "expected.chunks")); $expectedChunksCollection->insertMany($data['chunks']); $this->collections['expected.chunks'] = $expectedChunksCollection; } if (isset($test['arrange'])) { foreach ($test['arrange']['data'] as $cmd) { foreach ($cmd as $key => $value) { if (isset($this->commands[$key])) { $collection = new Collection($this->manager, sprintf("%s.%s", $this->getDatabaseName(), $cmd[$key])); $this->commands[$key]($collection, $this->fixTypes($cmd, true)); } } } } }
protected function tearDown() { self::$collection->drop(); }
protected function tearDown() { if (!is_null($this->userCollection)) { $this->userCollection->drop(); } }
/** * @return void */ public function clear() { $this->collection->drop(); }