[Question] Query object of object inside an array #2320
Unanswered
adhasahar97
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The contact collection:
[ { _id:1, "phones": [ { "label": "Home", "country": { "name": "Singapore", "dial_code": "+60", "code": "SG" }, "value": "xxxxx", "_default": true, "whatsapp": true }, { "label": "Personal", "country": { "name": "Singapore", "dial_code": "+60", "code": "SG" }, "value": "xxxxx", "_default": true, "whatsapp": true } ] }, { _id:2, "phones": [ { "label": "Home", "country": { "name": "Malaysia", "dial_code": "+60", "code": "MY" }, "value": "xxxxx", "_default": true, "whatsapp": true } ] } ]
If there a way to convert this
db.contact.find({'phones':{$elemMatch:{'country.code':'MY'}}})
I tried
contact_search::whereRaw(['phones'=>['$elemMatch'=>['country.code'=>'MY']]])
and it doesn't work. ThanksBeta Was this translation helpful? Give feedback.
All reactions