Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify Docs about all #3291

Open
masterbater opened this issue Feb 27, 2025 · 1 comment
Open

Clarify Docs about all #3291

masterbater opened this issue Feb 27, 2025 · 1 comment

Comments

@masterbater
Copy link
Contributor

masterbater commented Feb 27, 2025

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();
@masterbater masterbater changed the title [Feature Request] Clarify Docs about all Clarify Docs about all Feb 27, 2025
@GromNaN
Copy link
Member

GromNaN commented Feb 27, 2025

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

@GromNaN GromNaN added the docs label Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants