2022-10-31 11:52:17 +08:00
|
|
|
# Filter Operators
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Used in the filter paramaters of the `find`, `findOne`, `findAndCount`, `count`, etc. APIs of repository:
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
const repository = db.getRepository('books');
|
|
|
|
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$eq: 'Spring and Autumn',
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
To support JSON, NocoBase identifies query operators as a string prefixed with $.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Moreover, NocoBase provides API to extend operators. Refer to [`db.registerOperators()`](../database#registeroperators).
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
## General Operators
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
### `$eq`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value is equal to the specified value. Equivalent to `=` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$eq: 'Spring and Autumn',
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Equal to `title: 'Spring and Autumn'`
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
### `$ne`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value is not equal to the specified value. Equivalent to `!=` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$ne: 'Spring and Autumn',
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$is`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value is the specified value. Equivalent to `IS` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
|
|
|
$is: null,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$not`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value is not the specified value. Equivalent to `IS NOT` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
|
|
|
$not: null,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$col`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value is equal to the value of another field. Equivalent to `=` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
|
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
|
|
|
$col: 'name',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$in`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value is in the specified array. Equivalent to `IN` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$in: ['Spring and Autumn', 'Warring States'],
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$notIn`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value is not in the specified array. Equivalent to `NOT IN` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$notIn: ['Spring and Autumn', 'Warring States'],
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$empty`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the general field is empty. For string field, check if it is an empty string; for array field, check if it is an empty array.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
|
|
|
$empty: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$notEmpty`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the general field is not empty. For string field, check if it is not an empty string; for array field, check if it is not an empty array.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
|
|
|
$notEmpty: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
## Logical Operators
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
### `$and`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Logical AND. Equivalent to `AND` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
$and: [
|
2023-01-27 23:02:33 +08:00
|
|
|
{ title: 'Book of Songs' },
|
2022-10-31 11:52:17 +08:00
|
|
|
{ isbn: '1234567890' },
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$or`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Logical OR. Equivalent to `OR` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
$or: [
|
2023-01-27 23:02:33 +08:00
|
|
|
{ title: 'Book of Songs' },
|
2022-10-31 11:52:17 +08:00
|
|
|
{ publishedAt: { $lt: '0000-00-00T00:00:00Z' } },
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
## Boolean Field Operators
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
For boolean fields: `type: 'boolean'`
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
### `$isFalsy`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if a Boolean field value is false. Boolean field values of `false`, `0` and `NULL` are all judged to be `$isFalsy: true`.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
isPublished: {
|
|
|
|
$isFalsy: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$isTruly`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if a Boolean field value is true. Boolean field values of `true` and `1` are all judged to be `$isTruly: true`.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
isPublished: {
|
|
|
|
$isTruly: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
## Numeric Type Field Operators
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
For numeric type fields, including:
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
- `type: 'integer'`
|
|
|
|
- `type: 'float'`
|
|
|
|
- `type: 'double'`
|
|
|
|
- `type: 'real'`
|
|
|
|
- `type: 'decimal'`
|
|
|
|
|
|
|
|
### `$gt`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value is greater than the specified value. Equivalent to `>` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
price: {
|
|
|
|
$gt: 100,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$gte`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value is equal to or greater than the specified value. Equivalent to `>=` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
price: {
|
|
|
|
$gte: 100,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$lt`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value is less than the specified value. Equivalent to `<` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
price: {
|
|
|
|
$lt: 100,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$lte`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value is equal to or less than the specified value. Equivalent to `<=` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
price: {
|
|
|
|
$lte: 100,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$between`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value is between the specified two values. Equivalent to `BETWEEN` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
price: {
|
|
|
|
$between: [100, 200],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$notBetween`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value is not between the specified two values. Equivalent to `NOT BETWEEN` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
price: {
|
|
|
|
$notBetween: [100, 200],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
## String Type Field Operators
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
For string type fields, including `string`.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
### `$includes`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the string field contains the specified substring.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$includes: 'Three Character Classic',
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$notIncludes`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the string field does not contain the specified substring.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$notIncludes: 'Three Character Classic',
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$startsWith`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the string field starts with the specified substring.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$startsWith: 'Three Character Classic',
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$notStatsWith`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the string field does not start with the specified substring.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$notStatsWith: 'Three Character Classic',
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$endsWith`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the string field ends with the specified substring.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$endsWith: 'Three Character Classic',
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$notEndsWith`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the string field does not end with the specified substring.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$notEndsWith: 'Three Character Classic',
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$like`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value contains the specified string. Equivalent to `LIKE` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$like: 'Computer',
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$notLike`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value does not contain the specified string. Equivalent to `NOT LIKE` in SQL.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$notLike: 'Computer',
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$iLike`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if a field value contains the specified string, case ignored. Equivalent to `ILIKE` in SQL (PG only).
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
|
|
|
$iLike: 'Computer',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$notILike`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if a field value does not contain the specified string, case ignored. Equivalent to `NOT ILIKE` in SQL (PG only).
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
|
|
|
$notILike: 'Computer',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$regexp`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value matches the specified regular expression. Equivalent to `REGEXP` in SQL (PG only).
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$regexp: '^Computer',
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$notRegexp`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value does not matche the specified regular expression. Equivalent to `NOT REGEXP` in SQL (PG only).
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$notRegexp: '^Computer',
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$iRegexp`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value matches the specified regular expression, case ignored. Equivalent to `~*` in SQL (PG only).
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
|
|
|
$iRegexp: '^COMPUTER',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$notIRegexp`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the field value does not matche the specified regular expression, case ignored. Equivalent to `!~*` in SQL (PG only).
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
title: {
|
|
|
|
$notIRegexp: '^COMPUTER',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
## Date Type Field Operators
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
For date type fields: `type: 'date'`
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
### `$dateOn`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the date field value is within a certain day.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
createdAt: {
|
|
|
|
$dateOn: '2021-01-01',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$dateNotOn`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the date field value is not within a certain day.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
createdAt: {
|
|
|
|
$dateNotOn: '2021-01-01',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$dateBefore`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the date field value is before a certain value, i.e. less than the one passed in.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
createdAt: {
|
|
|
|
$dateBefore: '2021-01-01T00:00:00.000Z',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$dateNotBefore`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the date field value is not before a certain value, i.e. equal to or greater than the one passed in.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
createdAt: {
|
|
|
|
$dateNotBefore: '2021-01-01T00:00:00.000Z',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$dateAfter`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the date field value is after a certain value, i.e. greater than the one passed in.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
createdAt: {
|
|
|
|
$dateAfter: '2021-01-01T00:00:00.000Z',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$dateNotAfter`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the date field value is not after a certain value, i.e. equal to or greater than the one passed in.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
createdAt: {
|
|
|
|
$dateNotAfter: '2021-01-01T00:00:00.000Z',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
## Array Type Field Operators
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
For array type fields: `type: 'array'`
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
### `$match`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the array field values match values of the specified array.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
tags: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$match: ['literature', 'history'],
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$notMatch`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the array field values do not match values of the specified array.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
tags: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$notMatch: ['literature', 'history'],
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$anyOf`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the array field values contain any of the values of the specified array.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
tags: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$anyOf: ['literature', 'history'],
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$noneOf`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the array field values contain none of the values of the specified array.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
tags: {
|
2023-01-27 23:02:33 +08:00
|
|
|
$noneOf: ['literature', 'history'],
|
2022-10-31 11:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$arrayEmpty`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the array field is empty.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
tags: {
|
|
|
|
$arrayEmpty: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$arrayNotEmpty`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
Check if the array field is not empty.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
tags: {
|
|
|
|
$arrayNotEmpty: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
## Relational Field Type Operators
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
For checking if a relationship exists, field types include:
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
- `type: 'hasOne'`
|
|
|
|
- `type: 'hasMany'`
|
|
|
|
- `type: 'belongsTo'`
|
|
|
|
- `type: 'belongsToMany'`
|
|
|
|
|
|
|
|
### `$exists`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
There is relational data existing.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
author: {
|
|
|
|
$exists: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `$notExists`
|
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
There is no relational data existing.
|
2022-10-31 11:52:17 +08:00
|
|
|
|
2023-01-27 23:02:33 +08:00
|
|
|
**Example**
|
2022-10-31 11:52:17 +08:00
|
|
|
|
|
|
|
```ts
|
|
|
|
repository.find({
|
|
|
|
filter: {
|
|
|
|
author: {
|
|
|
|
$notExists: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|