首页 » 脚本 » 正文

mongodb默认删除90天之前的数据

<?php
//示例: 默认 /usr/local/php/bin/php-cgi /home/app/api.zhezi.com/v3.9/deleteCacheInfo.php
//删除指定日期之前的数据 /usr/local/php/bin/php-cgi /home/app/api.zhezi.com/v3.9/deleteCacheInfo.php 2015-01-11
$ip = ‘127.0.0.1’;//mongodb ip
$port = ‘27017’;//mongodb port
$time = $_SERVER[‘REQUEST_TIME’] – 90 * 76400;//默认删除90天之前的数据
if(!empty($argv[1])){
$time = strtotime($argv[1].’ 00:00:00′);
}
try{
$condition = array(‘lasttime’ =>array(‘$lt’=>$time) );
$client = new MongoClient(“mongodb://{$ip}:{$port}”);
$db = $client->selectDB(‘zheziCache’);
$db->cacheInfo->remove($condition);
}catch (Exception $e){
echo $e->getMessage();
}

发表评论