Filtering with the Query Engine API
In most cases you should not use the Query Engine API and rather use the Document Service API.
Only use the Query Engine API if you exactly know what you are doing, for instance if you want to use a lower-level API that directly interacts with unique rows of the database.
Please keep in mind that the Query Engine API is not aware of the most advanced Strapi 5 features like Draft & Publish, Internationalization, Content History, and possibly more.
The Query Engine API offers the ability to filter results found with its findMany() method.
Results are filtered with the where
parameter that accepts logical operators and attribute operators. Every operator should be prefixed with $
.
Logical operatorsβ
$and
β
All nested conditions must be true
.
Example
const entries = await strapi.db.query('api::article.article').findMany({
where: {
$and: [
{
title: 'Hello World',
},
{
createdAt: { $gt: '2021-11-17T14:28:25.843Z' },
},
],
},
});
$and
is used implicitly when passing an object with nested conditions:
const entries = await strapi.db.query('api::article.article').findMany({
where: {
title: 'Hello World',
createdAt: { $gt: '2021-11-17T14:28:25.843Z' },
},
});
$or
β
One or many nested conditions must be true
.
Example
const entries = await strapi.db.query('api::article.article').findMany({
where: {
$or: [
{
title: 'Hello World',
},
{
createdAt: { $gt: '2021-11-17T14:28:25.843Z' },
},
],
},
});