O'Reilly logo

Node.js, MongoDB, and AngularJS Web Development by Brad Dayley

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

Adding Indexes

MongoDB allows you to index fields in your collections so that you can more quickly find documents. When you add an index in MongoDB, a special data structure is created in the background that stores a small portion of a collection’s data and then optimizes the structure of that data to make it faster to find specific documents.

For example, applying an _id index basically creates a sorted array of _id values. Once the index has been created, you get these benefits:

Image When looking up an object by _id, you can perform an optimized search on the ordered index to find the object in question.

Say that you want objects back sorted by ...

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