MongoDB Create Databases and Collections
MongoDB Create Databases and Collections- MongoDB stores data in a Database → Collection → Document structure.
Database → Like a container for collections (similar to a database in SQL).
Collection → Like a table in SQL, it contains multiple documents.
Document → A JSON-like object that stores actual data.

Create a Database
use database_name
If myDatabase doesn’t exist, it will create a new database.
For checking the current database:
db
To show all databases:
show dbs

Create a Collection
db.createCollection("collection_name") // syntax
db.createCollection("students")
This will create an empty collection named students.
To view collections in the current DB:
show collections
Delete a Collection
The drop() method is used to delete an entire collection from a database in MongoDB.
Once a collection is dropped, all documents inside it are permanently deleted and cannot be recovered.
db.collection_name.drop()
db → Refers to the current database.
collection_name → Name of the collection you want to delete.
drop() → Removes the collection.
Drop a collection of students
db.students.drop()
Output will be:
true
Drop the Entire Database
db.dropDatabase()
This will delete the whole database, including all collections.
