There is a sub-field called 'name' in MongoDB Collection (User):
[
{
"teacher": {
"name": "Alex",
"email": "alex@domain.com"
},
"waiter": {
"name": "Feliks",
"email": "feliks@domain.com"
},
"pilot": [
{
"name": "Sam",
"email": "sam@domain.com"
},
{
"name": "alice",
"email": "alice@domain.com"
}
],
},
{
"teacher": {
"name": "max",
"email": "max@domain.com"
},
"waiter": {
"name": "Sam",
"email": "sam@domain.com"
},
"pilot": [
{
"name": "richard",
"email": "richard@domain.com"
},
{
"name": "alice",
"email": "alice@domain.com"
}
],
}
]
How can I find data based on the field 'name'. For example, when I'm looking for 'Sam', it should return me the all documents since 'Sam' is in "waiter" and "pilot" in first and second documents respectively.
I cannot do something like:
User.find({"teacher.name": "Sam", "waiter.name": "Sam", "pilot.name": "Sam" })
This will return me nothing as it is an AND logic. What I need is an OR logic.