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

docs: add descriptions of all match operators #2552

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion docs/content/3.composables/1.query-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,27 @@ const contentQuery = queryContent('articles', 'nuxt3')

Filter results by query.

Where queries are based on subset of [Mongo query syntax](https://www.mongodb.com/docs/manual/reference/operator/query), it handles: `$eq`, `$ne`, `$gt`, `$gte`, `$lt`, `$lte` and `$in`
Where queries are based on subset of [Mongo query syntax](https://www.mongodb.com/docs/manual/reference/operator/query), it handles:

| Operator | Description |
|----------------|-------------------------------------------------------------------------------|
| `$match` | – |
| `$eq` | Match if item equals condition |
| `$ne` | Match if item not equals condition |
| `$not` | Match is condition is false |
| `$and` | Match only if all of nested conditions are true |
| `$or` | Match if any of nested conditions is true |
| `$in` | Match if item is in condition array |
| `$contains` | Match if item contains every condition or match every rule in condition array |
| `$icontains` | Ignore case contains |
| `$containsAny` | Match if item contains at least one rule from condition array |
| `$exists` | Check key existence |
| `$type` | Match if type of item equals condition |
| `$regex` | Provides regular expression capabilities for pattern matching strings |
| `$lt` | Check if item is less than condition |
| `$lte` | Check if item is less than or equal to condition |
| `$gt` | Check if item is greater than condition |
| `$gte` | Check if item is greater than or equal to condition |

```ts
// Implicit (assumes $eq operator)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/query/match/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function createOperators (match: (...args: any[]) => boolean, operators: Record<
),

/**
* Match if item contains every condition or math every rule in condition array
* Match if item contains every condition or match every rule in condition array
**/
$contains: (item, condition) => {
item = Array.isArray(item) ? item : String(item)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export interface QueryBuilderWhere extends Partial<Record<keyof ParsedContentInt
*/
$exists?: boolean
/**
* Match if item contains every condition or math every rule in condition array
* Match if item contains every condition or match every rule in condition array
*
* @example
```ts
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/types/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export interface ContentQueryBuilderWhere extends Partial<Record<keyof ParsedCon
*/
$exists?: boolean
/**
* Match if item contains every condition or math every rule in condition array
* Match if item contains every condition or match every rule in condition array
*
* @example
```ts
Expand Down