0

I know you could do Coll.findOne({ email_1: 'abc@somedomain.com' }) to look up abc@somedomain.com against the field email_1 in collection Coll. However, what if there were several email fields (email_1, email_2, email_3, etc.) and I needed to look up a given email against all those fields?

I could reiterate Coll.findOne({ email_1: 'abc@somedomain.com' }) for each field in my collection but that obviously isn't most optimal.

TheLearner
  • 2,813
  • 5
  • 46
  • 94
  • 2
    A similar question like your. [Just look it] (https://stackoverflow.com/questions/6790819/searching-for-value-of-any-field-in-mongodb-without-explicitly-naming-it). May be helpful. – Nasir Kamal Jul 30 '19 at 15:06
  • 1
    As far as I know I'm not aware of anything, unless we do it in code. Interested to learn if someone has a query solution. – whoami - fakeFaceTrueSoul Jul 30 '19 at 15:09
  • 1
    I believe that, if possible in your case, the best way would be changing the schema to something like `"emails": ["email1@test.com","email2@test.com","email3@test.com"]` – Caconde Jul 30 '19 at 15:09
  • Possible duplicate of [Searching for value of any field in MongoDB without explicitly naming it](https://stackoverflow.com/questions/6790819/searching-for-value-of-any-field-in-mongodb-without-explicitly-naming-it) – TheLearner Jul 30 '19 at 15:18

0 Answers0