Skip to main content

文档服务 API:过滤器

¥Document Service API: Filters

文档服务 API 提供了过滤结果的能力。

¥The Document Service API offers the ability to filter results.

可以使用以下运算符:

¥The following operators are available:

运算符描述
$eq平等的
$eqi等于(不区分大小写)
$ne不等于
$nei不等于(不区分大小写)
$lt少于
$lte小于或等于
$gt比...更棒
$gte大于或等于
$in包含在数组中
$notIn不包含在数组中
$contains包含
$notContains不含
$containsi包含(不区分大小写)
$notContainsi不包含(不区分大小写)
$null一片空白
$notNull不为空
$between在。。。之间
$startsWith以。。开始
$startsWithi开头为(不区分大小写)
$endsWith以。。结束
$endsWithi结尾为(不区分大小写)
$or连接 "or" 表达式中的过滤器
$and连接 "and" 表达式中的过滤器
$not连接 "not" 表达式中的过滤器

属性运算符

¥Attribute operators

$not

否定嵌套条件。

¥Negates the nested condition(s).

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: {
$not: {
$contains: 'Hello World',
},
},
},
});

$eq

属性等于输入值。

¥Attribute equals input value.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: {
$eq: 'Hello World',
},
},
});

$eq 可以省略:

¥$eq can be omitted:



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: 'Hello World',
},
});

$eqi

属性等于输入值(不区分大小写)。

¥Attribute equals input value (case-insensitive).

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: {
$eqi: 'HELLO World',
},
},
});

$ne

属性不等于输入值。

¥Attribute does not equal input value.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: {
$ne: 'ABCD',
},
},
});

$nei

属性不等于输入值(不区分大小写)。

¥Attribute does not equal input value (case-insensitive).

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: {
$nei: 'abcd',
},
},
});

$in

属性包含在输入列表中。

¥Attribute is contained in the input list.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: {
$in: ['Hello', 'Hola', 'Bonjour'],
},
},
});

传递值数组时可以省略 $in

¥$in can be omitted when passing an array of values:



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: ['Hello', 'Hola', 'Bonjour'],
},
});

$notIn

输入列表中不包含属性。

¥Attribute is not contained in the input list.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: {
$notIn: ['Hello', 'Hola', 'Bonjour'],
},
},
});

$lt

属性小于输入值。

¥Attribute is less than the input value.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
rating: {
$lt: 10,
},
},
});

$lte

属性小于或等于输入值。

¥Attribute is less than or equal to the input value.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
rating: {
$lte: 10,
},
},
});

$gt

属性大于输入值。

¥Attribute is greater than the input value.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
rating: {
$gt: 5,
},
},
});

$gte

属性大于或等于输入值。

¥Attribute is greater than or equal to the input value.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
rating: {
$gte: 5,
},
},
});

$between

属性位于 2 个输入值之间,包括边界(例如,$between[1, 3] 还将返回 13)。

¥Attribute is between the 2 input values, boundaries included (e.g., $between[1, 3] will also return 1 and 3).

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
rating: {
$between: [1, 20],
},
},
});

$contains

属性包含输入值(区分大小写)。

¥Attribute contains the input value (case-sensitive).

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: {
$contains: 'Hello',
},
},
});

$notContains

属性不包含输入值(区分大小写)。

¥Attribute does not contain the input value (case-sensitive).

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: {
$notContains: 'Hello',
},
},
});

$containsi

属性包含输入值。$containsi 不区分大小写,而 $包含 则区分大小写。

¥Attribute contains the input value. $containsi is not case-sensitive, while $contains is.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: {
$containsi: 'hello',
},
},
});

$notContainsi

属性不包含输入值。$notContainsi 不区分大小写,而 $不包含 则区分大小写。

¥Attribute does not contain the input value. $notContainsi is not case-sensitive, while $notContains is.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: {
$notContainsi: 'hello',
},
},
});

$startsWith

属性以输入值开始。

¥Attribute starts with input value.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: {
$startsWith: 'ABCD',
},
},
});

$endsWith

属性以输入值结尾。

¥Attribute ends with input value.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: {
$endsWith: 'ABCD',
},
},
});

$null

属性为 null

¥Attribute is null.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: {
$null: true,
},
},
});

$notNull

属性不是 null

¥Attribute is not null.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: {
$notNull: true,
},
},
});

逻辑运算符

¥Logical operators

$and

所有嵌套条件必须为 true

¥All nested conditions must be true.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
$and: [
{
title: 'Hello World',
},
{
createdAt: { $gt: '2021-11-17T14:28:25.843Z' },
},
],
},
});

当传递具有嵌套条件的对象时,将隐式使用 $and

¥$and will be used implicitly when passing an object with nested conditions:



const entries = await strapi.documents('api::article.article').findMany({


filters: {
title: 'Hello World',
createdAt: { $gt: '2021-11-17T14:28:25.843Z' },
},
});

$or

一个或多个嵌套条件必须为 true

¥One or many nested conditions must be true.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
$or: [
{
title: 'Hello World',
},
{
createdAt: { $gt: '2021-11-17T14:28:25.843Z' },
},
],
},
});

$not

否定嵌套条件。

¥Negates the nested conditions.

示例

¥Example



const entries = await strapi.documents('api::article.article').findMany({


filters: {
$not: {
title: 'Hello World',
},
},
});
✏️ 注意

$not 可用作:

¥$not can be used as:

  • 逻辑运算符(例如在 filters: { $not: { // conditions… }} 中)

    ¥a logical operator (e.g. in filters: { $not: { // conditions… }})

  • 属性运算符(例如在 filters: { attribute-name: $not: { … } } 中)。

    ¥an attribute operator (e.g. in filters: { attribute-name: $not: { … } }).

💡 提示

$and$or$not 运算符可嵌套在另一个 $and$or$not 运算符内。

¥$and, $or and $not operators are nestable inside of another $and, $or or $not operator.