从 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() 方法显示一个集合中的所有文档。查询如下:
> 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 中完全删除了集合。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP