Is it a good practice to use .equalTo("colName", undefined)?

I have a field that can have 3 states: true, false and undefined.

Each represents a different scenario.

  1. Would using query.equalTo("colName", undefined) be more performant as it would allow utilizing an index vs query.notContainedIn("colName", [true, false]) ? or will the value of undefined prevent MongoDB from utilizing the index, and therefore I should go with notContainedIn?

  2. Also would query.equalTo("colName", undefined) be better than query.doesNotExist("colName") ?

Thank you

Hi @andreisu if you read JS SDK docs you have the “exists” query constraint

In term of good practice about performance , it’s not really related to Parse but about common backends best practices:

  • add indexes on fields used by many queries
  • avoid negative queries

You have also a section about this in the docs JavaScript Developers Guide | Parse

But it’s not related to Parse, it’s some common best practices on backend/apis

1 Like