dropCollection
Description
dropCollection(
drops an existing collection from MongoDB® by using the MongoDB C++ interface connection.conn
,collection
)
Examples
Drop Collection in MongoDB
Connect to MongoDB® using the MongoDB C++ interface and drop an existing collection.
Create a MongoDB connection to the database mongotest
using the MongoDB C++ interface. Here, the database server dbtb01
hosts this database using port number 27017
.
server = "dbtb01"; port = 27017; dbname = "mongotest"; conn = mongoc(server,port,dbname)
conn = connection with properties:
Database: "mongotest"
UserName: ""
Server: "dbtb01"
Port: 27017
CollectionNames: [14×1 string]
conn
is the connection
object that contains the MongoDB connection. The object properties contain information about the connection and the database.
The database name is
mongotest
.The user name is blank.
The database server is
dbtb01
.The port number is
27017
.This database contains 14 document collections.
Verify the MongoDB connection.
isopen(conn)
ans = logical
1
The database connection is successful because the isopen
function returns 1. Otherwise, the database connection is closed.
Display the collections in the database before dropping a collection by using the CollectionNames
property.
conn.CollectionNames
ans = 14×1 string
"dateissue"
"product"
"timestamps"
"restaurants"
"employees"
"bsontest"
"taxidata"
"airlinesmall"
"largedata"
"patients"
"genderMeanAge"
"escalation"
"nyctaxi"
"tsunamis"
Drop an existing collection from the database by using the MongoDB connection. Specify the collection name taxidata
.
collection = "taxidata";
dropCollection(conn,collection)
Display the collections in the database again by using the CollectionNames
property. The database no longer contains the collection taxidata
.
conn.CollectionNames
ans = 13×1 string
"dateissue"
"product"
"timestamps"
"restaurants"
"employees"
"bsontest"
"airlinesmall"
"largedata"
"patients"
"genderMeanAge"
"escalation"
"nyctaxi"
"tsunamis"
Close the MongoDB connection.
close(conn)
Input Arguments
conn
— MongoDB C++ interface connection
connection
object
MongoDB C++ interface connection, specified as a connection
object.
collection
— Collection name
string scalar
Collection name, specified as a string scalar.
Example: "taxidata"
Data Types: string
Version History
Introduced in R2021b
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)