0

Configuration of remote server: Ubuntu 20.04 on Digital ocean (1vcpu, 1GM Ram, 25GB memory) MongoDb running on Digital ocean machine

Local machine: MacOS, Dockerized Nodejs express server (from here I am searching through my collections)

I created 2 collections in my DB, one is indexed (PartnerModelIndex) and another not (PartnerModel).

  • See picture:

enter image description here

I created 2 API routes on my NodeJS - only one of them searches through indexed collection:

enter image description here

I also filled my collections with 1.000.000 (million) documents with following parameters:

  • title - has approximately 20-30 words (each document)
  • description - has approximately 5k - 6k characters (each document)

enter image description here

Here is my MongoDB compass showing the occupied memory by indexes:

The problem is that when I try to search for any non-existent string in my database (through title and description) I get the same execution time for both indexed and non-indexed collection, see image

enter image description here

And non-indexed:

enter image description here

What could be the reason for this strange behavior? Thank you in advance!

spatak
  • 1,039
  • 1
  • 14
  • 25

1 Answers1

0

When evaluating the clauses in the $or expression, MongoDB either performs a collection scan or, if all the clauses are supported by indexes, MongoDB performs index scans. That is, for MongoDB to use indexes to evaluate an $or expression, all the clauses in the $or expression must be supported by indexes. Otherwise, MongoDB will perform a collection scan.

Ref: https://www.mongodb.com/community/forums/t/why-is-mongodb-not-taking-an-existing-unique-compound-index-for-an-or-query/103229

bhavesh
  • 453
  • 3
  • 11