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();

Activity

changed the title [-][Feature Request] Clarify Docs about all[/-] [+]Clarify Docs about all[/+] on Feb 27, 2025
GromNaN

GromNaN commented on Feb 27, 2025

@GromNaN
Member

You're right, the all operator is just the $all. The description should be identical between the Laravel-MongoDB doc and the operator doc.

The tests show that:

yield 'where all' => [
['find' => [['tags' => ['$all' => ['ssl', 'security']]], []]],
fn (Builder $builder) => $builder->where('tags', 'all', ['ssl', 'security']),
];
yield 'where all nested operators' => [
[
'find' => [
[
'tags' => [
'$all' => [
['$elemMatch' => ['size' => 'M', 'num' => ['$gt' => 50]]],
['$elemMatch' => ['num' => 100, 'color' => 'green']],
],
],
],
[],
],
],
fn (Builder $builder) => $builder->where('tags', 'all', [
['$elemMatch' => ['size' => 'M', 'num' => ['$gt' => 50]]],
['$elemMatch' => ['num' => 100, 'color' => 'green']],
]),
];

Internally tracked for review by the docs team: DOCSP-47950

added theissue type on Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @GromNaN@masterbater

        Issue actions

          Clarify Docs about all · Issue #3291 · mongodb/laravel-mongodb