批量刪除mongo collections

header("content-type:text/html; charset=utf-8");


/**
 * 批量刪除mongo collections
 */
//http://php.net/manual/zh/mongodb.getcollectionnames.php
//http://www.php.net/manual/en/mongodb.dropcollection.php
$MongoHost = "mongodb://************";
$connection = new Mongo($MongoHost);


$connections = $connection->selectDB("collections");
$CollectionNames = $connections->getCollectionNames();


foreach ($CollectionNames as $Names) {
    $coupon_receive_1 = "xxx_1"; //需要刪除的名稱前綴
    $coupon_receive_2 = "xxx_2";
    $name = substr($Names , 0, 16); //截取字符串做匹配
    if($name == $coupon_receive_2  || $name == $coupon_receive_1 ){
        echo $Names . "<br>";
        echo ++$i;
        $a = $connections->dropCollection($Names);
        usleep(100);
    }    
}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章