remove() public method

Remove records from this collection
public remove ( array $criteria = [], array $options = [] ) : boolean | array
$criteria array Query criteria for the documents to delete.
$options array An array of options for the remove operation.
return boolean | array Returns an array containing the status of the removal if the "w" option is set. Otherwise, returns TRUE.
Beispiel #1
0
 public function deleteExceedingQuota($quota)
 {
     $threshold = 0.9 * $quota;
     $currentSize = $this->getPictureTotalSize();
     $counter = 0;
     if ($currentSize > $threshold) {
         $toPurge = $currentSize - $threshold;
         // cleaning
         $cursor = $this->collection->find(['-class' => 'picture'], ['storageKey' => true, 'size' => true])->sort(['_id' => 1]);
         // starting from older pictures
         $sum = 0;
         foreach ($cursor as $item) {
             if ($sum < $toPurge) {
                 $this->storage->remove($item['storageKey']);
                 $this->collection->remove(['_id' => $item['_id']]);
                 $sum += $item['size'];
                 $counter++;
             } else {
                 // when we have deleted enough old pictures to reach the exceeding size to purge
                 break;
             }
         }
     }
     return $counter;
 }
Beispiel #2
0
 /**
  */
 public function purge()
 {
     try {
         $this->_db->remove(array(self::TIMESTAMP => array('$lt' => time() - $this->_params['timeout'])));
     } catch (MongoException $e) {
         throw new Horde_Token_Exception($e);
     }
 }
Beispiel #3
0
 /**
  * Delete all Publishing content with their pk
  *
  * @param array $listing flat array given by the query above
  * @see self::findMostReportedPublish()
  */
 public function batchDeletePublish(array $listing)
 {
     $compilPk = [];
     foreach ($listing as $item) {
         $compilPk[] = $item['_id'];
     }
     $this->collection->remove(['_id' => ['$in' => $compilPk]]);
 }
Beispiel #4
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;
 }
 public function gc($maxLifeTime)
 {
     $query = array('time' => array('$lt' => time() - $maxLifeTime));
     try {
         $this->collection->remove($query);
         return true;
     } catch (MongoCursorException $ex) {
         return false;
     }
 }
 /**
  * Lets you remove documents based on a criteria
  * 
  * @param Array $criteria the conditions for removing documents
  */
 public function remove($criteria = array())
 {
     ValidatorsUtil::isNullOrEmpty($this->_mongoCollection, "Mongo collection isn't valid, have you set a collection?");
     $this->_mongoCollection->remove($criteria);
     $this->_count = 0;
     $this->_id = "";
 }
Beispiel #7
0
 /**
  * Execute the remove query.
  *
  * @see Collection::remove()
  * @param array $query
  * @param array $options
  * @return array|boolean
  */
 protected function doRemove(array $query, array $options)
 {
     $options = isset($options['safe']) ? $this->convertWriteConcern($options) : $options;
     $options = isset($options['wtimeout']) ? $this->convertWriteTimeout($options) : $options;
     $options = isset($options['timeout']) ? $this->convertSocketTimeout($options) : $options;
     return $this->mongoCollection->remove($query, $options);
 }
Beispiel #8
0
 /**
  */
 protected function _deleteOldEntries($before)
 {
     try {
         $this->_db->remove(array(self::TS => array('$lt' => $before)));
     } catch (MongoException $e) {
     }
 }
Beispiel #9
0
 /**
  * Deletes an item from the cache store.
  *
  * @param string $key The key to delete.
  * @return bool Returns true if the operation was a success, false otherwise.
  */
 public function delete($key)
 {
     if (!is_array($key)) {
         $criteria = array('key' => $key);
     } else {
         $criteria = $key;
     }
     $options = array('justOne' => false);
     if ($this->legacymongo) {
         $options['safe'] = $this->usesafe;
     } else {
         $options['w'] = $this->usesafe ? 1 : 0;
     }
     $result = $this->collection->remove($criteria, $options);
     if ($result === true) {
         // Safe mode.
         return true;
     } else {
         if (is_array($result)) {
             if (empty($result['ok']) || isset($result['err'])) {
                 return false;
             } else {
                 if (empty($result['n'])) {
                     // Nothing was removed.
                     return false;
                 }
             }
             return true;
         }
     }
     // Who knows?
     return false;
 }
Beispiel #10
0
 /**
  * Added by me
  * 
  * Finds messages matching the query and removes from queue
  * @param array $query in same format as \MongoCollection::find() where top level fields do not contain operators.
  * Lower level fields can however. eg: valid {a: {$gt: 1}, "b.c": 3}, invalid {$and: [{...}, {...}]}
  * @param bool $logging whether logging is enabled or not 
  * @param array $logdata optional log data to be stored in _processed collection
  * @return void
  *
  * @throws \InvalidArgumentException key in $query was not a string
  */
 public function delqueues(array $query, $logging = false, $logdata = array())
 {
     if (!is_bool($logging)) {
         throw new \InvalidArgumentException('$logging was not a bool');
     }
     $removeQuery = array();
     foreach ($query as $key => $value) {
         if (!is_string($key)) {
             throw new \InvalidArgumentException('key in $query was not a string');
         }
         $removeQuery["payload.{$key}"] = $value;
     }
     if (count($removeQuery) > 0) {
         if ($logging && $this->_collection_processed != null) {
             $cursor = $this->_collection->find($removeQuery);
             foreach ($cursor as $doc) {
                 if ($doc !== null && array_key_exists('_id', $doc)) {
                     $deleted_message = array('payload' => $doc['payload'], 'log' => $logdata, 'pts' => new \MongoDate(), 'qd' => true);
                     $this->_collection_processed->insert($deleted_message);
                 }
             }
         }
         // remove queues
         $this->_collection->remove($removeQuery);
     }
 }
Beispiel #11
0
 /**
  * Delete the object
  *
  */
 function delete()
 {
     if ($this->_collection && $this->_id) {
         $this->_collection->remove(array("_id" => $this->_id));
     }
     $this->_id = null;
     $this->_attrs = array();
 }
 /**
  * Deletes a document from the model's collection
  * @param array $criteria Description of records to remove.
  * @param array $options Options for remove. see @link http://www.php.net/manual/en/mongocollection.remove.php
  * @return mixed If "safe" is set, returns an associative array with the status of the remove ("ok"), the number of items removed ("n"), and any error that may have occured ("err"). Otherwise, returns TRUE if the remove was successfully sent, FALSE otherwise.
  * Throws MongoCursorException if the "safe" option is set and the remove fails. Throws MongoCursorTimeoutException if the "safe" option is set and the operation takes longer than MongoCursor::$timeout milliseconds to complete. This does not kill the operation on the server, it is a client-side timeout.
  */
 public function remove($criteria, $options = array())
 {
     if ($options === null) {
         $options = array();
     }
     $criteria = self::_sanitize($criteria);
     return $this->collection->remove($criteria, $options);
 }
 /**
  * The garbage collection function invoked by PHP.
  * @param  int     $lifetime The lifetime param, defaults to 1440 seconds in PHP.
  * @return boolean True always.
  */
 public function gc($lifetime = 0)
 {
     $timeout = $this->getConfig('timeout');
     //find all sessions that are older than $timeout
     $olderThan = time() - $timeout;
     //no ack required
     $this->sessions->remove(array('last_accessed' => array('$lt' => new MongoDate($olderThan))), class_exists('MongoClient') ? array('w' => 0) : array('safe' => false));
     return true;
 }
Beispiel #14
0
 function remove($filter, $options = array())
 {
     br()->log()->writeln('MONGO->REMOVE', "QRY");
     br()->log()->writeln($filter, "FLT");
     br()->log()->writeln($options, "OPT");
     $result = parent::remove($filter, $options);
     br()->log()->writeln('Query complete', 'SEP');
     return $result;
 }
Beispiel #15
0
 /**
  */
 public function gc($maxlifetime = 300)
 {
     try {
         $this->_db->remove(array(self::MODIFIED => array('$lt' => time() - $maxlifetime)));
         return true;
     } catch (MongoException $e) {
     }
     return false;
 }
Beispiel #16
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.
      */
     $result = $this->mongoCollection->remove(array($this->options->getModifiedField() => array('$lt' => new MongoDate(time() - $maxlifetime))), $this->options->getSaveOptions());
     return (bool) (isset($result['ok']) ? $result['ok'] : $result);
 }
Beispiel #17
0
 /**
  * Do garbage collection needed for the driver.
  */
 public function gc()
 {
     try {
         $result = $this->_db->remove(array(self::EXPIRY_TS => array('$lt' => time(), '$ne' => Horde_Lock::PERMANENT)));
         if ($this->_logger) {
             $this->_logger->log(sprintf('Lock garbage collection cleared %d locks.', $result['n']), 'DEBUG');
         }
     } catch (MongoException $e) {
     }
 }
Beispiel #18
0
 /**
  * Delete documents by expression
  * 
  * @param callable|array|\Sokil\Mongo\Expression $expression
  * @return \Sokil\Mongo\Collection
  * @throws Exception
  */
 public function batchDelete($expression = array())
 {
     // remove
     $result = $this->_mongoCollection->remove(Expression::convertToArray($expression));
     // check result
     if (true !== $result && $result['ok'] != 1) {
         throw new Exception('Error removing documents from collection: ' . $result['err']);
     }
     return $this;
 }
Beispiel #19
0
 /**
  * {@inheritdoc}
  */
 public function flush($all = false)
 {
     if (true === $all) {
         $res = $this->db->drop();
         return (bool) $res['ok'];
     }
     // $res = $this->collection->drop();
     $regex = new \MongoRegex('/^' . $this->mapKey('') . '/');
     $res = $this->collection->remove(array('key' => $regex));
     return (bool) $res['ok'];
 }
Beispiel #20
0
 /**
  * Remove row
  *
  * @param array $row Row to remove
  * @return MongoDB
  * @throws RuntimeException
  */
 private function removeRow(array $row)
 {
     if (!isset($row['_id'])) {
         throw new RuntimeException('Could not delte. Missing _id attribute.');
     }
     $status = $this->collection->remove(array('_id' => $row['_id']), array('w' => 1));
     if ($status['err'] !== null) {
         throw new RuntimeException('Failed to remove row with error: ' . $status['err']);
     }
     return $this;
 }
 public function testSafeRemove2()
 {
     $result = $this->object->remove(array(), array("safe" => true));
     $this->assertEquals(true, (bool) $result['ok']);
     $this->assertEquals(0, $result['n']);
     $this->assertNull($result['err']);
     $this->object->batchInsert(array(array("x" => 1), array("x" => 1), array("x" => 1)));
     $result = $this->object->remove(array(), array("safe" => true));
     $this->assertEquals(true, (bool) $result['ok']);
     $this->assertEquals(3, $result['n']);
     $this->assertNull($result['err']);
 }
Beispiel #22
0
 /**
  * Removes document from mongo
  *
  * @param mixed $document
  * @param array $options Array of options to be used with remove()
  * @throws \Doctrine\ODM\MongoDB\LockException
  */
 public function delete($document, array $options = array())
 {
     $id = $this->uow->getDocumentIdentifier($document);
     $query = array('_id' => $this->class->getDatabaseIdentifierValue($id));
     if ($this->class->isLockable) {
         $query[$this->class->lockField] = array('$exists' => false);
     }
     $result = $this->collection->remove($query, $options);
     if (($this->class->isVersioned || $this->class->isLockable) && !$result['n']) {
         throw LockException::lockFailed($document);
     }
 }
Beispiel #23
0
 /**
  */
 public function expire($key)
 {
     $okey = $key;
     $key = $this->_getCid($key);
     try {
         $this->_db->remove(array(self::CID => $key));
         $this->_logger->log(sprintf('Cache expire: %s (cache ID %s)', $okey, $key), 'DEBUG');
         return true;
     } catch (MongoException $e) {
         return false;
     }
 }
 /**
  * Removes document from mongo
  *
  * @param mixed $document
  * @param array $options Array of options to be used with remove()
  * @throws \Doctrine\ODM\MongoDB\LockException
  */
 public function delete($document, array $options = array())
 {
     $query = $this->getQueryForDocument($document);
     if ($this->class->isLockable) {
         $query[$this->class->lockField] = array('$exists' => false);
     }
     $options = $this->getWriteOptions($options);
     $result = $this->collection->remove($query, $options);
     if (($this->class->isVersioned || $this->class->isLockable) && !$result['n']) {
         throw LockException::lockFailed($document);
     }
 }
 function eliminaDeTablaTemporal($TABLA, $CONDICION)
 {
     $DATOS = array();
     $IDIOMAS = new Idiomas();
     try {
         $DB = $this->CONEXION->innet;
         $COLECCION = new MongoCollection($DB, "temporal" . $TABLA);
         $COLECCION->remove($CONDICION);
     } catch (Exception $e) {
         $this->LOG->registraLog("Generica", $e->getMessage(), "No es posible eliminar datos de la tabla temporal " . $TABLA);
         return false;
     }
 }
function mongodb_fixture()
{
    $db_name = DB_NAME;
    $host_path = "mongodb://" . HOST . ":" . PORT;
    $mongodb = new MongoDB(new Mongo($host_path), $db_name);
    $collection_name = COLLECTION_NAME;
    $collection = new MongoCollection($mongodb, $collection_name);
    $collection->remove(array());
    //remove all documents of that collection
    $fixture = array(array('_id' => 1, 'tags' => array('dog', 'cat')), array('_id' => 2, 'tags' => array('cat')), array('_id' => 3, 'tags' => array('mouse', 'cat', 'dog')), array('_id' => 4, 'tags' => array()));
    $collection->batchInsert($fixture, array('safe' => true));
    return $mongodb;
}
 public function delete($collectionName, $array)
 {
     #gelen $tableName isimli collectiona bağlantı gerçekleştirelim.
     $Collection = new MongoCollection($this->mongodb, $collectionName);
     //kayıt silme
     try {
         $Collection->remove($array, array('safe' => true));
         $result = 'Başarılı şekilde silme işlemi gerçekleştirilmişir.';
     } catch (MongoCursorException $e) {
         die('Silme işlemi yaparken teknik bir sorunla karşılaşıldı ' . $e->getMessage());
     }
     return $result;
 }
 /**
  * Removes documents from the client collection that have
  * an lrs_id that does not exist in the lrs collection.
  *
  * @return void
  */
 public function up()
 {
     $db = \DB::getMongoDB();
     $clients = new MongoCollection($db, 'client');
     $lrss = new MongoCollection($db, 'lrs');
     $clientCursor = $clients->find([], ['lrs_id' => true]);
     foreach ($clientCursor as $client) {
         $count = $lrss->count(['_id' => $client['lrs_id']]);
         if ($count == 0) {
             $clients->remove(['_id' => $client['_id']]);
         }
     }
 }
Beispiel #29
0
 /**
  * Destroy Session - remove data from resource for
  * given session id
  *
  * @param string $id
  */
 public function destroy($id)
 {
     try {
         $session = $this->_collection->findOne(array('_id' => $id));
         $this->_collection->remove(array('_id' => $id), array('multiple' => false));
         if (isset($session['rawData']['Zend_Auth']['storage']['token'])) {
             $watcherCollection = $this->_connection->watcher;
             $watcherCollection->remove(array('scope' => 'token', 'scopeId' => $session['rawData']['Zend_Auth']['storage']['token']), array('w' => 0, 'multiple' => true));
         }
     } catch (Exception $e) {
     }
     return true;
 }
Beispiel #30
0
 /**
  * Deletes an item from the cache store.
  *
  * @param string $key The key to delete.
  * @return bool Returns true if the operation was a success, false otherwise.
  */
 public function delete($key)
 {
     if (!is_array($key)) {
         $criteria = array('key' => $key);
     } else {
         $criteria = $key;
     }
     $options = array('justOne' => false, 'safe' => $this->usesafe);
     $result = $this->collection->remove($criteria, $options);
     if ($result === false || is_array($result) && !array_key_exists('ok', $result) || $result === 0) {
         return false;
     }
     return !empty($result['ok']);
 }