Indexing increases the query performance tremendously but causes some overheads in write operations. We will learn in great detail about the various types of indexes in the next chapter. When we index fields, it's important to maintain the right order. For example, for the Book
model, if we will always search by the title, and then maybe by the author and published date, it makes sense to create a compound index.
class Book ... index({title: 1, author: 1, published_date: 1} end
So, if we now try to search for books and the title is present, it will always use the BTreeCursor
indexed search that is faster. However, if the title is not used in searches, the BasicCursor
function is relatively slower.