# Query Engine API: Populating
Relations and components have a unified API for populating them.
To populate all the root level relations, use populate: true
:
strapi.db.query('api::article.article').findMany({
populate: true,
});
1
2
3
2
3
Select which data to populate by passing an array of attribute names:
strapi.db.query('api::article.article').findMany({
populate: ['componentA', 'relationA'],
});
1
2
3
2
3
An object can be passed for more advanced usage:
strapi.db.query('api::article.article').findMany({
populate: {
componentB: true,
dynamiczoneA: true,
relation: someLogic || true,
},
});
1
2
3
4
5
6
7
2
3
4
5
6
7
Complex populating can also be achieved by applying where
filters and select or populate nested relations:
strapi.db.query('api::article.article').findMany({
populate: {
relationA: {
where: {
name: {
$contains: 'Strapi',
},
},
},
repeatableComponent: {
select: ['someAttributeName'],
orderBy: ['someAttributeName'],
populate: {
componentRelationA: true,
},
},
dynamiczoneA: true,
},
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
When dealing with polymorphic data structures (dynamic zones, polymorphic relations, etc...), it is possible to use populate fragments to have a better granularity on the populate strategy.
strapi.db.query('api::article.article').findMany('api::article.article', {
populate: {
dynamicZone: {
on: {
'components.foo': {
select: ['title'],
where: { title: { $contains: 'strapi' } },
},
'components.bar': {
select: ['name'],
},
},
},
morphAuthor: {
on: {
'plugin::users-permissions.user': {
select: ['username'],
},
'api::author.author': {
select: ['name'],
},
},
},
},
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26