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

Add $size #354

Merged
merged 9 commits into from
Apr 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions docs/jsonapi-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -1419,26 +1419,22 @@ The `$all` operation allows users to check for documents that have an array fiel

If provided to a `find()`, return all the documents where the locations field contains the two values – “New York” and “Texas”. It does not matter how many more values the locations field contains. The operation will match if the specified values are present. Similarly, if even one the value is missing, the document will not be matched. So the `$all` operation is useful while retrieving data.

The `$all` is equivalent to an `$and` operation of the specified values. For example, this first statement:
#### $elemMatch operation

```json5
{ tags: { $all: [ "ssl" , "security" ] } }
```
TODO:

... is equivalent to:
#### $size operation

```json5
{ $and: [ { tags: "ssl" }, { tags: "security" } ] }
The `$size` operation allows users to match any array with the number of elements specified by the argument. Example:

```json5
db.collection.find( { field: { $size: 2 } } );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't valid JSON. I think this should be { "field": { "$size": 2 } }

```

#### $elemMatch operation

TODO:
That expression returns, e.g.: `{ field: [ red, green ] }` and `{ field: [ apple, lime ] }`, but not `{ field: fruit }` or `{ field: [ orange, lemon, grapefruit ] }`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quotes around "field" and string values, so { "field": ["red", "green"] }. We should use valid JSON where possible for consistency and so code samples are easier to copy/paste.


#### $size operation
If the given field is not an array, there's no match. `$size` should ignore non-arrays.

TODO:

### Projection Clause

Expand Down