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 (I didn’t choose to persist them this way, but need to get around it now.
db.userCollection.createIndex({firebaseUid: 1, emails.apple: 1, emails.google: 1, phoneNumber: 1, emails.facebook: 1, emails.password: 1})