从MongoDB中删除带有特殊字符的集合?
为了删除具有_或-等特殊字符的集合,您需要使用以下语法-
db.getCollection("yourCollectionName").drop();为了理解这个概念,让我们用文档创建一个集合。使用文档创建集合的查询如下-
> db.createCollection("_personalInformation");
{ "ok" : 1 }
> db.getCollection('_personalInformation').insertOne({"ClientName":"Chris","ClientCountryName":"US"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9158bb4afe5c1d2279d6b2")
}
> db.getCollection('_personalInformation').insertOne({"ClientName":"Mike","ClientCountryName":"UK"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9158c84afe5c1d2279d6b3")
}
> db.getCollection('_personalInformation').insertOne({"ClientName":"David","ClientCountryName":"AUS"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9158d54afe5c1d2279d6b4")
}在find()method的帮助下显示集合中的所有文档。查询如下-
> db.getCollection('_personalInformation').find().pretty();以下是输出-
{
"_id" : ObjectId("5c9158bb4afe5c1d2279d6b2"),
"ClientName" : "Chris",
"ClientCountryName" : "US"
}
{
"_id" : ObjectId("5c9158c84afe5c1d2279d6b3"),
"ClientName" : "Mike",
"ClientCountryName" : "UK"
}
{
"_id" : ObjectId("5c9158d54afe5c1d2279d6b4"),
"ClientName" : "David",
"ClientCountryName" : "AUS"
}这是从MongoDB中删除具有特殊字符的集合的查询-
> db.getCollection("_personalInformation").drop();以下是输出-
True
结果TRUE表示我们已经从MongoDB中完全删除了该集合。
热门推荐
10 给宝贝开学祝福语简短
11 买房的祝福语高级简短
12 祝贺开业文案祝福语简短
13 毕业送礼老师祝福语简短
14 男友人新婚祝福语简短
15 虎年开新车祝福语简短
16 儿媳买车妈妈祝福语简短
17 姐妹分手了祝福语简短
18 父母生孩子祝福语简短