DocumentationHelp CenterDocumentation
Drop MongoDB collection
dropCollection(conn,collection)
example
dropCollection(conn,collection) drops an existing collection from MongoDB® by using the MongoDB connection.
conn
collection
collapse all
Connect to MongoDB and drop a collection.
Create a MongoDB connection to the database mongotest. Here, the database server dbtb01 hosts this database using port number 27017.
mongotest
dbtb01
27017
server = "dbtb01"; port = 27017; dbname = "mongotest"; conn = mongo(server,port,dbname)
conn = mongo with properties: Database: 'mongotest' UserName: '' Server: {'dbtb01'} Port: 27017 CollectionNames: {'airlinesmall', 'employee', 'largedata' ... and 3 more} TotalDocuments: 23485919
conn is the mongo object that contains the MongoDB connection. The object properties contain information about the connection and the database.
mongo
The database name is mongotest.
The user name is blank.
The database server is dbtb01.
The port number is 27017.
This database contains six document collections. The first three collection names are airlinesmall, employee, and largedata.
airlinesmall
employee
largedata
This database contains 23,485,919 documents.
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.
isopen
1
Display the collections in the database before dropping a collection by using the CollectionNames property.
CollectionNames
conn.CollectionNames
ans = 1×7 cell array Columns 1 through 5 {'airlinesmall'} {'employee'} {'largedata'} {'nyctaxi'} {'product'} Columns 6 through 7 {'restaurants'} {'taxidata'}
Drop an existing collection from the database by using the MongoDB connection. Specify the collection name taxidata.
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.
ans = 1×7 cell array Columns 1 through 5 {'airlinesmall'} {'employee'} {'largedata'} {'nyctaxi'} {'product'} Columns 6 {'restaurants'}
Close the MongoDB connection.
close(conn)
MongoDB connection, specified as a mongo object.
Collection name, specified as a string scalar.
Example: "taxidata"
"taxidata"
Data Types: string
string
close | createCollection | find | isopen | mongo
close
createCollection
find
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office