Example #1
0
 /**
  * @param string $identity
  * @return void
  */
 public function delete(string $identity)
 {
     if ($this->collection->count([$this->identityField => $identity]) == 0) {
         return;
     }
     $this->collection->deleteOne([$this->identityField => $identity]);
 }
Example #2
0
 /**
  * @param string $id
  */
 public function unlock($id)
 {
     $result = $this->collection->deleteOne(['_id' => new ObjectID((string) $id), 'sessionId' => $this->sessionId]);
     if (false == $result->isAcknowledged()) {
         throw new \LogicException(sprintf('Cannot unlock id %s. The deleteOne operation is not acknowledged.', $id));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function remove($key)
 {
     KeyUtil::validate($key);
     try {
         $result = $this->collection->deleteOne(array('_id' => $key));
         $deletedCount = $result->getDeletedCount();
     } catch (Exception $e) {
         throw WriteException::forException($e);
     }
     return $deletedCount > 0;
 }
 /**
  * Acknowledge a message was processed and remove from queue.
  *
  * @param array $message message received from get()
  *
  * @return void
  *
  * @throws \InvalidArgumentException $message does not have a field "id" that is a MongoDB\BSON\ObjectID
  */
 public function ack(array $message)
 {
     $id = null;
     if (array_key_exists('id', $message)) {
         $id = $message['id'];
     }
     if (!is_a($id, 'MongoDB\\BSON\\ObjectID')) {
         throw new \InvalidArgumentException('$message does not have a field "id" that is a ObjectID');
     }
     $this->collection->deleteOne(['_id' => $id]);
 }
Example #5
0
 /**
  * @param object $model
  * @param array  $options
  *
  * @return \MongoDB\DeleteResult
  */
 public function delete($model, array $options = [])
 {
     $modelId = get_object_id($model);
     $values = get_object_values($model);
     unset($values['_id']);
     $result = $this->collection->deleteOne(['_id' => new ObjectID($modelId)], $options);
     if (false == $result->isAcknowledged()) {
         throw new \LogicException('Operation is not acknowledged');
     }
     return $result;
 }
Example #6
0
 public function deleteOne($filter, array $options = [])
 {
     $collectionName = $this->collection->getCollectionName();
     $textQuery = json_encode($filter);
     $textOptions = json_encode($options);
     Yii::trace("Executing deleteOne: {\$query: {$textQuery}, \$options: {$textOptions} }", "mongoyii\\Collection");
     if ($this->client->enableProfiling) {
         Yii::beginProfile("mongoyii\\{$collectionName}.deleteOne({\$query: {$textQuery}, \$options: {$textOptions} })", 'mongoyii\\Collection.deleteOne');
     }
     $res = $this->collection->deleteOne($filter, $options);
     if ($this->client->enableProfiling) {
         Yii::endProfile("mongoyii\\{$collectionName}.deleteOne({\$query: {$textQuery}, \$options: {$textOptions} })", 'mongoyii\\Collection.deleteOne');
     }
     return $res;
 }
Example #7
0
 /**
  * @param Persistable $model
  * @param array       $options
  *
  * @return \MongoDB\DeleteResult
  */
 public function delete(Persistable $model, array $options = [])
 {
     $bson = $model->bsonSerialize();
     if (is_array($bson)) {
         $modelId = $bson['_id'];
         unset($bson['_id']);
     } else {
         $modelId = $bson->_id;
         unset($bson->_id);
     }
     $result = $this->collection->deleteOne(['_id' => new ObjectID($modelId)], $options);
     if (false == $result->isAcknowledged()) {
         throw new \LogicException('Operation is not acknowledged');
     }
     return $result;
 }
 public function remove($id)
 {
     CodeGuard::checkTypeAndThrow($id, 'string');
     $result = $this->_collection->deleteOne(array('_id' => self::mongoID($id)));
     return $result->getDeletedCount();
 }
Example #9
0
 /**
  * Destroy session
  *
  * @param string $id
  * @return bool
  */
 public function destroy($id)
 {
     $result = $this->mongoCollection->deleteOne(['_id' => $id, $this->options->getNameField() => $this->sessionName], $this->options->getSaveOptions());
     return $result->isAcknowledged();
 }
Example #10
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);
         }
     }
 }
Example #11
0
 /**
  * @param SavableModelInterface $model
  * @return void
  */
 public function purge(SavableModelInterface $model)
 {
     $this->collection->deleteOne(array('id' => $model->getId()));
     $model->markAsStored();
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function deleteOne($filter, array $options = [])
 {
     $event = $this->startQueryLogging(__FUNCTION__, $filter, null, $options);
     $result = parent::deleteOne($filter, $options);
     $this->logger->logQuery($event);
     return $result;
 }
 /**
  * @see DataModelInterface::delete
  */
 public function delete($id)
 {
     $result = $this->db->deleteOne(array('_id' => new ObjectId($id)));
     return $result->getDeletedCount();
 }