本文整理汇总了PHP中MongoCollection::remove方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoCollection::remove方法的具体用法?PHP MongoCollection::remove怎么用?PHP MongoCollection::remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCollection
的用法示例。
在下文中一共展示了MongoCollection::remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteExceedingQuota
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;
}
示例2: purge
/**
*/
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);
}
}
示例3: batchDeletePublish
/**
* 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]]);
}
示例4: purge
/**
* {@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;
}
示例5: gc
public function gc($maxLifeTime)
{
$query = array('time' => array('$lt' => time() - $maxLifeTime));
try {
$this->collection->remove($query);
return true;
} catch (MongoCursorException $ex) {
return false;
}
}
示例6: remove
/**
* 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 = "";
}
示例7: doRemove
/**
* 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);
}
示例8: _deleteOldEntries
/**
*/
protected function _deleteOldEntries($before)
{
try {
$this->_db->remove(array(self::TS => array('$lt' => $before)));
} catch (MongoException $e) {
}
}
示例9: delete
/**
* 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;
}
示例10: delqueues
/**
* 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);
}
}
示例11: delete
/**
* Delete the object
*
*/
function delete()
{
if ($this->_collection && $this->_id) {
$this->_collection->remove(array("_id" => $this->_id));
}
$this->_id = null;
$this->_attrs = array();
}
示例12: remove
/**
* 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);
}
示例13: gc
/**
* 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;
}
示例14: remove
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;
}
示例15: gc
/**
*/
public function gc($maxlifetime = 300)
{
try {
$this->_db->remove(array(self::MODIFIED => array('$lt' => time() - $maxlifetime)));
return true;
} catch (MongoException $e) {
}
return false;
}