> For the complete documentation index, see [llms.txt](https://docs.bashschool.in/v1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bashschool.in/v1/javascript/mongodb/mongodb-databases-and-collections.md).

# 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:

```
use databaseName
```

#### 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:

```
db.collectionName.insert({name: "John Doe", age: 30})
```

Replace `collectionName` with the desired name for your collection.

To drop (delete) a collection, use the `drop()` method:

```
db.collectionName.drop()
```

#### Dropping a Database

To drop (delete) a database, first, switch to the database you want to drop:

```
use databaseName
```

Then, use the `dropDatabase()` command:

```
db.dropDatabase()
```
