public function unlockAll()
 {
     $result = $this->collection->deleteMany(['sessionId' => $this->sessionId]);
     if (false == $result->isAcknowledged()) {
         throw new \LogicException('Cannot unlock all locked ids. The deleteMany operation is not acknowledged.');
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function purge()
 {
     if ($this->collection instanceof \MongoDB\Collection) {
         $this->collection->deleteMany(['expiration' => ['$lte' => time()]]);
     } else {
         $this->collection->remove(['expiration' => ['$lte' => time()]], ['multiple' => true]);
     }
     return true;
 }
Beispiel #3
0
 /**
  * Garbage collection
  *
  * Note: MongoDB 2.2+ supports TTL collections, which may be used in place
  * of this method by indexing the "modified" field with an
  * "expireAfterSeconds" option. Regardless of whether TTL collections are
  * used, consider indexing this field to make the remove query more
  * efficient.
  *
  * @see http://docs.mongodb.org/manual/tutorial/expire-data/
  * @param int $maxlifetime
  * @return bool
  */
 public function gc($maxlifetime)
 {
     /* Note: unlike DbTableGateway, we do not use the lifetime field in
      * each document. Doing so would require a $where query to work with the
      * computed value (modified + lifetime) and be very inefficient.
      */
     $microseconds = floor(microtime(true) * 1000) - $maxlifetime;
     $result = $this->mongoCollection->deleteMany([$this->options->getModifiedField() => ['$lt' => new UTCDateTime($microseconds)]], $this->options->getSaveOptions());
     return $result->isAcknowledged();
 }
Beispiel #4
0
 public function deleteMany($filter, array $options = [])
 {
     $collectionName = $this->collection->getCollectionName();
     $textQuery = json_encode($filter);
     $textOptions = json_encode($options);
     Yii::trace("Executing deleteMany: {\$query: {$textQuery}, \$options: {$textOptions} }", "mongoyii\\Collection");
     if ($this->client->enableProfiling) {
         Yii::beginProfile("mongoyii\\{$collectionName}.deleteMany({\$query: {$textQuery}, \$options: {$textOptions} })", 'mongoyii\\Collection.deleteMany');
     }
     $res = $this->collection->deleteMany($filter, $options);
     if ($this->client->enableProfiling) {
         Yii::endProfile("mongoyii\\{$collectionName}.deleteMany({\$query: {$textQuery}, \$options: {$textOptions} })", 'mongoyii\\Collection.deleteMany');
     }
     return $res;
 }
Beispiel #5
0
 /**
  * Run a truncate statement on the table.
  */
 public function truncate()
 {
     $result = $this->collection->deleteMany([]);
     return $result->isAcknowledged();
 }
Beispiel #6
0
 /**
  * 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);
         }
     }
 }
Beispiel #7
0
 /**
  * {@inheritdoc}
  */
 public function deleteMany($filter, array $options = [])
 {
     $event = $this->startQueryLogging(__FUNCTION__, $filter, null, $options);
     $result = parent::deleteMany($filter, $options);
     $this->logger->logQuery($event);
     return $result;
 }