To create an index in MongoDB, use the `db.collection.createIndex()` method.
Here’s a general syntax:
```
db.collection.createIndex({
```
Where:
- `
- `
For example, if you want to create an ascending index on the `name` field in the `customers` collection, you would write:
```
db.customers.createIndex({name: 1})
```
If you want to create a unique index where duplicate values are not allowed:
```
db.customers.createIndex({name: 1}, {unique: true})
```
Create a name for the index in the optional parameter:
```
db.customers.createIndex({name: 1}, {unique: true, name: “index_on_name”})
```
And to check the indexes on a collection:
```
db.customers.getIndexes()
```
Be careful when creating indexes. While they can speed up read operations, they also use storage space and can slow down write operations. Consider your application’s requirements before deciding to create an index.