# Query Engine API: Single Operations
# findOne()
Finds the first entry matching the parameters.
Syntax: findOne(parameters) ⇒ Entry
# Parameters
Parameter | Type | Description |
---|---|---|
select | String, or Array of strings | Attributes to return |
where | WhereParameter | Filters to use |
offset | Integer | Number of entries to skip |
orderBy | OrderByParameter | Order definition |
populate | PopulateParameter | Relations to populate |
# Example
const entry = await strapi.db.query('api::blog.article').findOne({
select: ['title', 'description'],
where: { title: 'Hello World' },
populate: { category: true },
});
1
2
3
4
5
2
3
4
5
# findMany()
Finds entries matching the parameters.
Syntax: findMany(parameters) ⇒ Entry[]
# Parameters
Parameter | Type | Description |
---|---|---|
select | String, or Array of strings | Attributes to return |
where | WhereParameter | Filters to use |
limit | Integer | Number of entries to return |
offset | Integer | Number of entries to skip |
orderBy | OrderByParameter | Order definition |
populate | PopulateParameter | Relations to populate |
# Example
const entries = await strapi.db.query('api::blog.article').findMany({
select: ['title', 'description'],
where: { title: 'Hello World' },
orderBy: { publishedAt: 'DESC' },
populate: { category: true },
});
1
2
3
4
5
6
2
3
4
5
6
# findWithCount()
Finds and counts entries matching the parameters.
Syntax: findWithCount(parameters) => [Entry[], number]
# Parameters
Parameter | Type | Description |
---|---|---|
select | String, or Array of strings | Attributes to return |
where | WhereParameter | Filters to use |
limit | Integer | Number of entries to return |
offset | Integer | Number of entries to skip |
orderBy | OrderByParameter | Order definition |
populate | PopulateParameter | Relations to populate |
# Example
const [entries, count] = await strapi.db.query('api::blog.article').findWithCount({
select: ['title', 'description'],
where: { title: 'Hello World' },
orderBy: { title: 'DESC' },
populate: { category: true },
});
1
2
3
4
5
6
2
3
4
5
6
# create()
Creates one entry and returns it.
Syntax: create(parameters) => Entry
# Parameters
Parameter | Type | Description |
---|---|---|
select | String, or Array of strings | Attributes to return |
populate | PopulateParameter | Relations to populate |
data | Object | Input data |
# Example
const entry = await strapi.db.query('api::blog.article').create({
data: {
title: 'My Article',
},
});
1
2
3
4
5
2
3
4
5
# update()
Updates one entry and returns it.
Syntax: update(parameters) => Entry
# Parameters
Parameter | Type | Description |
---|---|---|
select | String, or Array of strings | Attributes to return |
populate | PopulateParameter | Relations to populate |
where | WhereParameter | Filters to use |
data | Object | Input data |
# Example
const entry = await strapi.db.query('api::blog.article').update({
where: { id: 1 },
data: {
title: 'xxx',
},
});
1
2
3
4
5
6
2
3
4
5
6
# delete()
Deletes one entry and returns it.
Syntax: delete(parameters) => Entry
# Parameters
Parameter | Type | Description |
---|---|---|
select | String, or Array of strings | Attributes to return |
populate | PopulateParameter | Relations to populate |
where | WhereParameter | Filters to use |
# Example
const entry = await strapi.db.query('api::blog.article').delete({
where: { id: 1 },
});
1
2
3
2
3