批量删除mongo collections

<?php
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);
    }    
}




发布了27 篇原创文章 · 获赞 53 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/auspi12341/article/details/52035717