# Handling aggregation & comparison operators

**URL:** <https://discuss.jsonapi.org/t/handling-aggregation-comparison-operators/241>\
**Category:** Uncategorized\
**Created:** [December 2, 2015, 9:27am UTC](https://discuss.jsonapi.org/t/handling-aggregation-comparison-operators/241 "2015-12-02T09:27:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mudassir0909](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/mudassir0909/32/151_2.png) [@mudassir0909](https://discuss.jsonapi.org/u/mudassir0909)\
**Post date:** [December 2, 2015, 9:27am UTC](https://discuss.jsonapi.org/t/handling-aggregation-comparison-operators/241/1 "2015-12-02T09:27:07Z")

</div>

Imagine a site like StackOverflow, Questions & Answers have to many relationship.

If I want to get most discussed questions, I’d do fetch questions whose `count(answers.*) > 10`

Similarly if I want to get all unanswered questions, I’d do fetch questions whose `count(answers.*) = 0`

Following are my attempts

```auto
GET api/questions?filters[answers __count__ gte]=10

```

```auto
GET api/questions?filters[answers__count]=0

```

OR

```auto
GET api/questions?filters[count(answers)]=0

```

Does these make sense? is there any standard way to do this?

---

<div class="post-metadata">

**Author:** ![ethanresnick](https://avatars.discourse-cdn.com/v4/letter/e/45deac/32.png) [@ethanresnick](https://discuss.jsonapi.org/u/ethanresnick)\
**Post date:** [December 3, 2015, 6:31am UTC](https://discuss.jsonapi.org/t/handling-aggregation-comparison-operators/241/2 "2015-12-03T06:31:59Z")

</div>

Any of those would be ok, and they all make sense conceptually.

Unfortunately, there isn’t yet a standard way to do this, but we’d love to have one eventually.

@dgeb @tkellen @steveklabnik Would you be up for creating a separate repo under the json-api organization where community members who are interested in trying to standardize `?filter` (which is a lot of work but seems like a worthwhile project), could discuss and try to put together draft proposals?

---

<div class="post-metadata">

**Author:** ![vvscode](https://avatars.discourse-cdn.com/v4/letter/v/58956e/32.png) [@vvscode](https://discuss.jsonapi.org/u/vvscode)\
**Post date:** [March 10, 2016, 9:51am UTC](https://discuss.jsonapi.org/t/handling-aggregation-comparison-operators/241/3 "2016-03-10T09:51:43Z")

</div>

@mudassir0909@ethanresnick can you share more information about selected solution? Maybe some article or examples for requests/respones ?  
Thx in advance

---

<div class="post-metadata">

**Author:** ![malras](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@malras](https://discuss.jsonapi.org/u/malras)\
**Post date:** [March 10, 2016, 12:29pm UTC](https://discuss.jsonapi.org/t/handling-aggregation-comparison-operators/241/4 "2016-03-10T12:29:59Z")

</div>

similar subject here: [http://discuss.jsonapi.org/t/share-propose-a-filtering-strategy/257](http://discuss.jsonapi.org/t/share-propose-a-filtering-strategy/257)

there is two proposal. my favorite is the one with `/filter[fieldName][$operator]=value`

but for the **count** I would hesitate between:

`GET api/questions?filter[count(answers)][$gte]=10`  
or  
`GET api/questions?filter[answers][$count][$gte]=10`

---

<div class="post-metadata">

**Author:** ![dmcwherter](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/dmcwherter/32/192_2.png) [@dmcwherter](https://discuss.jsonapi.org/u/dmcwherter)\
**Post date:** [March 17, 2016, 6:29pm UTC](https://discuss.jsonapi.org/t/handling-aggregation-comparison-operators/241/5 "2016-03-17T18:29:47Z")

</div>

Just want to +1 this. I feel having proper filtering is crucial for data exploration and-- eventually-- aggregations seems pretty crucial rather than having to do them out of spec.

---

<div class="post-metadata">

**Author:** ![jufemaiz](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/jufemaiz/32/296_2.png) [@jufemaiz](https://discuss.jsonapi.org/u/jufemaiz)\
**Post date:** [September 25, 2017, 7:41am UTC](https://discuss.jsonapi.org/t/handling-aggregation-comparison-operators/241/6 "2017-09-25T07:41:56Z")

</div>

Does seem to be another +1 to GraphQL for data based API…

---

<div class="post-metadata">

**Author:** ![michaelhibay](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/michaelhibay/32/405_2.png) [@michaelhibay](https://discuss.jsonapi.org/u/michaelhibay)\
**Post date:** [September 26, 2017, 2:07am UTC](https://discuss.jsonapi.org/t/handling-aggregation-comparison-operators/241/7 "2017-09-26T02:07:43Z")

</div>

Why is that exactly? There are 2 different elaborated strategies to be acceptably used on a RESTful API, and you don’t need to give up statelessness, cacheability, separation of concerns, and coherent uniform interface among other useful benefits.
