Skip to content

[Question] Query object of object inside an array #2319

@adhasahar97

Description

@adhasahar97
  • Laravel-mongodb Version: 3.7.x
  • PHP Version: 7.4
  • Database Driver & Version:

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. Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions