0

I have a very large database collection of around 540GB with 4 billion items.

The item contains various metadata but one important field "message" which is free text.

I would like to be able to query it for things like:

  • the message contains "error"
  • the message contains "password"
  • the message ends with "an error occurred"

What is the best type of index to create, and how can I create it?

I was also wondering if anyone had example queries?

I having been reading into text indexes and wildcard text indexes but I'm not sure what is the best fit.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Lemex
  • 3,772
  • 14
  • 53
  • 87

1 Answers1

1

A text index would be a good fit here:

db.mycoll.createIndex({ message: 'text' })

db.mycoll.find({ $text: { $search: 'error' } })
JohnnyHK
  • 305,182
  • 66
  • 621
  • 471