ProgrammingRookie
ProgrammingRookie

Reputation: 37

Parse DB/Mongo compound index with an OR and an Object

I am working on a project where the data is stored in a very weird shape that's causing the query for finding an user on first login attempt to TAKE A LONG TIME. I'm having a hard time wrapping my mind around how I can create an index for this. I want to find a single user. Any of these attributes can undefined, and I need to find a single user that match any of these (OR)

query.equalTo('firebaseUid', uid);
query.equalTo('emails.apple', email);
query.equalTo('emails.google', email);
query.equalTo('phoneNumber', phoneNumber);
query.equalTo('emails.facebook', email);
query.equalTo('emails.password', email);

Is this index correct or makes sense? I'm specifically lost on the fact that we are using find within an emails Object (Don't ask me why we are keeping them separate...). It's most likely an user has an UID than not (After first login). And from there I ordered from most likely login method based on user status (Mostly apple users, then google...)

db.userCollection.createIndex({firebaseUid: 1, emails.apple: 1, emails.google: 1, phoneNumber: 1, emails.facebook: 1, emails.password: 1})

Upvotes: 0

Views: 35

Answers (0)

Related Questions