Skip to content

Commit

Permalink
docs: add descriptions of all match operators (#2552)
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangDrescher authored Feb 13, 2024
1 parent d3b2d76 commit 1a3ef2e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
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

0 comments on commit 1a3ef2e

Please sign in to comment.