O'Reilly logo

Learning Mongoid by Gautam Rege

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Indexes

Indexing ensures faster reads. However, indexes have a hit on writes, that is, creation and updating of documents. There are various types of indexes supported by MongoDB. We have already seen these various types of indexes earlier.

Tip

Indexes are not automatically created. When we specify the index in our model, we need to run the rake db:mongoid:create_indexes command to create them. To get a list of database tasks that Mongoid supports, issue the rake –T db:mongoid command.

The following table gives a quick summary of the various options that are available for index creation:

Name

Example

Description

normal

index({name: 1})
index({name: 1}, {name: 'n' })
index({"address.location" => 1})

This is the typical index that gets created. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required