lion
March 7, 2023, 9:14am
1
System Information
Strapi Version : 4.7.1+
Operating System :
Database :
Node Version :
NPM Version :
Yarn Version :
Hi all! I use strapi to create a marketplace. I found that there are no aggregation functions in queries. This makes it difficult to use strapi for more or less serious projects.
Even in google sheets you can use formulas like =QUERY($A:$D; “select D, COUNT(D) where(B=‘Seen’) group by D limit 10”).
I’m sure there must be some way out. Tell him please?
You might make use of count?
const count = await strapi.db.query('api::blog.article').count({
where: {
title: {
$startsWith: 'v3',
},
},
});
Use Strapi's Entity Service API to perform CRUD (create, read, update, delete) operations on your content.
However for more aggregate-Functions there’s a PR that might come in near future.
strapi:master
← WalkingPizza:feature/avg-sum-aggregators
opened 05:18PM - 20 Mar 22 UTC
<!--
Hello 👋 Thank you for submitting a pull request.
To help us merge your … PR, make sure to follow the instructions below:
- Create or update the tests
- Create or update the documentation at https://github.com/strapi/documentation
- Refer to the issue you are closing in the PR description: Fix #issue
- Specify if the PR is ready to be merged or work in progress (by opening a draft PR)
Please ensure you read the Contributing Guide: https://github.com/strapi/strapi/blob/master/CONTRIBUTING.md
-->
### What does it do?
Adds the `avg` and `sum` functions to the Query Engine API.
### Why is it needed?
Just like the `count` aggregator, it is sometimes useful to retrieve sums and/or averages from the database directly instead of fetching entries and executing operations over them manually.
### How to test it?
1. Create a `Test` content type, with a numeric field called `value`;
2. Create a random amount of entries of type `Test`;
3. Run `strapi.db.query('api::data.data').sum("value");` and notice how it returns the sum of those values;
4. Run `strapi.db.query('api::data.data').avg("value");` and notice how it returns the average of those values.
Cheers,
Olaf
lion
March 7, 2023, 11:30am
3
Thanks
yes i know. But i need SUM )
In the documentation limit and start with what you can paginate CRUD operations | Strapi Documentation