-1

I a have collection named people and this collection have almost 100k documents..

While I am a front-end dev, I don't know How can I boost my search performance.

I do search as below:

const phoneNumbers = [
   { "phone": { "$regex": `1` } },
   { "phone": { "$regex": `2` } },
   { "phone": { "$regex": `3` } },
   { "phone": { "$regex": `4` } },
   { "phone": { "$regex": `5` } },
   { "phone": { "$regex": `xxx` } },
   { "phone": { "$regex": `999` } },
   { "phone": { "$regex": `1000` } },
];


peopleCollection.find({$or: phoneNumbers}).toArray((error, matchedDocs)=> {
   // returning matched docs
});

As you can see the structure of my search what is your suggestions to create index?

Is that helpful to create index ? If yes how Can I create a proper index ?

Belqis
  • 79
  • 1
  • 9
  • https://stackoverflow.com/questions/17501798/mongodb-performance-of-query-by-regular-expression-on-indexed-fields – Manvir Nov 07 '20 at 08:20

1 Answers1

0

Indexing does not reduce the complexity of your search expression, rather it helps the database to find out the matched result faster(i.e. reduce the time complexity).

Here is how you can create indexing:

db.collectionName.createIndex(key_name)

The above one-line operation creates indexing on key key_name.