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

本文介绍了一种批量删除MongoDB数据库中特定前缀的集合的方法。通过PHP脚本实现,该脚本连接到指定的MongoDB服务器,遍历目标数据库中的所有集合,并根据预设的名称前缀来确定是否删除每个集合。
1044

被折叠的 条评论
为什么被折叠?



