From 1a3ef2e674fa33d78f931bef73fe1a494e3cf760 Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Tue, 13 Feb 2024 11:07:43 +0100 Subject: [PATCH] docs: add descriptions of all match operators (#2552) --- docs/content/3.composables/1.query-content.md | 22 ++++++++++++++++++- src/runtime/query/match/index.ts | 2 +- src/runtime/types/index.ts | 2 +- src/runtime/types/query.ts | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/docs/content/3.composables/1.query-content.md b/docs/content/3.composables/1.query-content.md index 71da9711a..65df2b430 100644 --- a/docs/content/3.composables/1.query-content.md +++ b/docs/content/3.composables/1.query-content.md @@ -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) diff --git a/src/runtime/query/match/index.ts b/src/runtime/query/match/index.ts index 794e1213e..29b970b51 100644 --- a/src/runtime/query/match/index.ts +++ b/src/runtime/query/match/index.ts @@ -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) diff --git a/src/runtime/types/index.ts b/src/runtime/types/index.ts index f6036792c..678cc6952 100644 --- a/src/runtime/types/index.ts +++ b/src/runtime/types/index.ts @@ -361,7 +361,7 @@ export interface QueryBuilderWhere extends Partial