How to find with a component

Hi I have this kind of data :

{
id: 2,
name: ‘adidas2’,
model: ‘vdpozozdvz’,
complete_info: [
[{
hour: null,
price: ‘90’,
isnew: true,
}],
[{
hour: null,
price: ‘90’,
isnew: true,
}],
[{
hour: null,
price: ‘90’,
isnew: true,
}],

}

I’m doing a cron job that every day at midnight the “isnew” field in “complete_info” turn to false

so I find with strapi method all the response :

const res = await strapi.services.restaurant.find()

but what I want is to fond only the res with a “isnew” field at true

something like this :

const res = await strapi.services.restaurant.find({complete_info.isnew : true})
but I don’t understand the syntaxe to filter on the component

thank you :wink:

Hello, currently it’s not possible to filter reapetable components.

Take a look at this issue:

hi @sunnyson, and thank you for your awnser

my question echoed to this New Feature with cron and job - #8 by Gabriel_Eliade

where you tell me to get only elements wich have isnew equal to true

that’s why I was asking :wink:

Might have missed that it was a component, but Sunny is correct you can’t filter on components via Strapi methods, you will need to use the ORM directly or create a custom query

https://strapi.io/documentation/developer-docs/latest/concepts/queries.html#custom-queries

1 Like

The link directs to 404

1 Like

How to use mongoose to create a custom query to filter component value ?

Anyone have any idea how to filer components? @ sunnyson I’m new and I’m struggling with this one.

You can’t filter on components in the v3, this is a feature we are adding in our coming v4

I’m running v4 and still unable to find how to filter on components, neither with REST or GraphQL. Any idea?

3 Likes

any update on this in v4?
Thanks

I’m using replit here just to show how you would construct the filters and population in the qs package but you could also write the LHS bracket syntax manually. All of this is in our documentation.

Example QS structure:

Actual request:

Docs for REST: REST API - Strapi Developer Docs
Docs for GraphQL: GraphQL API - Strapi Developer Docs