Developer Ol
Developer Ol

Reputation: 112

Reasons for creating an Index for a string field in MongoDB

When I create an Index on a string-type field in MongoDB I get no significant speed boost from it. In fact, when I use the query:

db.movies.find({plot: /some text/}).explain("executionStats")

An Index is slowing down the query by 30-50% in my Database (~55k Docs).

I know, that I can use a "text" Index, which is working fine for me, but I was wondering, why you would create a "normal" Index on a string field.

Upvotes: 1

Views: 469

Answers (1)

sriharip316
sriharip316

Reputation: 456

Index on string fields will improve the performance of exact matches like,

db.movies.find({name: "some movie"})

Indexes will also be used for find queries with prefix expression,

db.movies.find({plot: /^begins with/})

Upvotes: 2

Related Questions