MongoDB Databases and Collections
Creating a Database
In MongoDB, databases are created implicitly when you first store data in them. You can create a new database using the use
command in the MongoDB shell:
Collections
Collections are analogous to tables in relational databases. They store documents (similar to rows in a table) with dynamic schemas.
To create a new collection, you can insert a document into it:
Replace collectionName
with the desired name for your collection.
To drop (delete) a collection, use the drop()
method:
Dropping a Database
To drop (delete) a database, first, switch to the database you want to drop:
Then, use the dropDatabase()
command:
Last updated
Was this helpful?