如何從 MongoDB 中刪除數字集合?
若要刪除數字集合名稱,請使用以下語法
db.getCollection("yourNumericCollectionName").drop();首先,建立一個數字集合。以下為查詢
> db.createCollection("2536464");
{ "ok" : 1 }現在在上述集合中插入一些文件。以下為查詢
> db.getCollection("2536464").insertOne({"Record":1});
{
"acknowledged" : true,
"insertedId" : ObjectId("5ca254a46304881c5ce84b8e")
}
> db.getCollection("2536464").insertOne({"Record":2});
{
"acknowledged" : true,
"insertedId" : ObjectId("5ca254a76304881c5ce84b8f")
}
> db.getCollection("2536464").insertOne({"Record":3});
{
"acknowledged" : true,
"insertedId" : ObjectId("5ca254a96304881c5ce84b90")
}以下為使用 find() 方法顯示集合中所有文件的查詢
> db.getCollection("2536464").find().pretty();這將生成以下輸出
{ "_id" : ObjectId("5ca254a46304881c5ce84b8e"), "Record" : 1 }
{ "_id" : ObjectId("5ca254a76304881c5ce84b8f"), "Record" : 2 }
{ "_id" : ObjectId("5ca254a96304881c5ce84b90"), "Record" : 3 }以下為刪除數字集合名稱的查詢
> db.getCollection("2536464").drop();這將生成以下輸出
True
現在數字集合名稱已成功刪除。
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP