Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to index, what to index in Mongoid?

I'm a bit new to indexes, but I am curious about the usecases for an index. (I assume it makes queries on the indexed fields much faster.) Is there a criteria for determining what to index and when to index? What kind of performance benefits should I expect -- specifically using Mongoid with MongoDb on a Rails app?

like image 864
picardo Avatar asked May 31 '11 06:05

picardo


People also ask

How does MongoDB decide which index to use?

MongoDB uses multikey indexes to index the content stored in arrays. If you index a field that holds an array value, MongoDB creates separate index entries for every element of the array. These multikey indexes allow queries to select documents that contain arrays by matching on element or elements of the arrays.

What is the use of index in mongoose?

Indexes are defined through ensureIndex every time a model is compiled for a certain connection / database. This means that indexes will only be ensured once during the lifetime of your app.

What is index in compass?

The index line fixed within the outer edge of the compass housing as an extension of the direction of travel arrow. It marks the bearing you set by rotating the compass housing.

Why do we need indexing in MongoDB?

MongoDB uses indexing in order to make the query processing more efficient. If there is no indexing, then the MongoDB must scan every document in the collection and retrieve only those documents that match the query.


1 Answers

Check out Indexes MongoDB docs and Indexing Advice and FAQ, lots of great info here.

like image 196
Chris Fulstow Avatar answered Sep 25 '22 17:09

Chris Fulstow