Document Service API: Filters
The Document Service API offers the ability to filter results.
The following operators are available:
| Operator | Description |
|---|---|
$eq | Equal |
$eqi | Equal (case-insensitive) |
$ne | Not equal |
$nei | Not equal (case-insensitive) |
$lt | Less than |
$lte | Less than or equal to |
$gt | Greater than |
$gte | Greater than or equal to |
$in | Included in an array |
$notIn | Not included in an array |
$contains | Contains |
$notContains | Does not contain |
$containsi | Contains (case-insensitive) |
$notContainsi | Does not contain (case-insensitive) |
$null | Is null |
$notNull | Is not null |
$between | Is between |
$startsWith | Starts with |
$startsWithi | Starts with (case-insensitive) |
$endsWith | Ends with |
$endsWithi | Ends with (case-insensitive) |
$or | Joins the filters in an "or" expression |
$and | Joins the filters in an "and" expression |
$not | Joins the filters in an "not" expression |
For examples of how to deep filter with the various APIs, please refer to this blog article.
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 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 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,
},
},
});