Skip to content

Clarify Docs about all #3291

Open
Open
@masterbater

Description

@masterbater

https://www.mongodb.com/docs/drivers/php/laravel-mongodb/current/query-builder/#contains-all-fields-example

It states that it scans all fields that exist, but what I know is that $all checks if all specified array match on the field that is an array

{
--
_id: ObjectId("5234cc89687ea597eabee675"),
code: "xyz",
tags: [ "school", "book", "bag", "headphone", "appliance" ],
qty: [
{ size: "S", num: 10, color: "blue" },
{ size: "M", num: 45, color: "blue" },
{ size: "L", num: 100, color: "green" }
]
}

{ tags: { $all: [ "ssl" , "security" ] } }
the behavior will be like this
{ $and: [ { tags: "ssl" }, { tags: "security" } ] }

But in laravel docs does mongodb $all has another behavior that check each fields( like $exist but in one go without loop)

{ "title": "Cosmos",
"year": 1980,
"runtime": 60,
"imdb": {
"rating": 9.3,
"votes": 17174,
"id": 81846
},
},

//Is this correct, or does mongodb $all has another behavior that check each fields( like $exist but in one go without loop)
$result = DB::table('movies')
    ->where('movies', 'all', ['title', 'rated', 'imdb.rating'])
    ->get();

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions