You can create unique indexes in MongoDB using the `createIndex` method in combination with the `unique` attribute.
Here is a simple example:
```
db.collection.createIndex( { “username”: 1 }, { unique: true } )
```
This command creates a unique index on the `username` field of the documents in a collection. The `unique` attribute ensures that the MongoDB rejects any insert or update that would result in duplicates of this field.
If you want to create a unique index on multiple fields, you can also do that:
```
db.collection.createIndex( { “username”: 1, “email”: 1 }, { unique: true } )
```
This command creates a unique index on the combination of `username` and `email` fields. So you can have two documents with the same username, and two documents with the same email, but you can’t have two documents with the same combination of username and email.
Note: Be aware that creating unique indexes might slow down operations like insert and update, but it can also speed up certain types of queries. So you will have to find a balance based on the usage pattern of your database.
Note: If you try to create unique index on a collection that already contains data, and this data includes duplicate values on the indexed field, the operation will fail.