0

I am trying to use the aggregations feature in RestHeart which is described here: https://restheart.org/docs/aggregations/

I am using it to filter and group stuff in my collection based on a input variable, like this.

https://.../_aggrs/test-pipeline?avars={"country":"DE"}

As the documentation states querying the aggregation does not yield the result directly, but I have to query the newly created collection. I found out that it also works to just query the aggregation endpoint twice. But in any case I have to make two requests to get the result.

I am now worried about concurrent users. If two users are querying the aggregation at the same time (with different avars), one might get the result of the other.

I am wondering why this is not mentioned anywhere. It seems to me that everybody should have this problem when using variables (avars) in an aggregation.

How can I solve this? Might transactions be the solution? https://restheart.org/docs/transactions/

I cannot try it right now, because my mongoDB is refusing to start a transaction. But would it even work?

Are there any other solutions?

Best regards, Tobi

Tobag
  • 170
  • 1
  • 10
  • 1
    are you using materialized views, i.e. the stage operator `$merge`, as described at https://restheart.org/docs/aggregations/#materialized-views? this would explain why you need two requests, one to create the materialized view and the second to get it. – Andrea Di Cesare Nov 27 '21 at 17:20
  • to have MongoDB supporting transactions you need to run it as a replica set. A single node replica set works too. see https://docs.mongodb.com/manual/tutorial/convert-standalone-to-replica-set/ – Andrea Di Cesare Nov 27 '21 at 17:21
  • Thank you @AndreaDiCesare. I didn't realize I could use the aggregations without the $merge stage, because it was in all the examples. I removed it and now it works with a single request like I wanted. Didn't think it would be that easy. – Tobag Nov 29 '21 at 07:17

0 Answers0