简体   繁体   English

使用RestHeart创建多个聚合

[英]Creating multiple aggregations using RestHeart

I am using RestHeart to make REST calls for MOngoDB aggregation queries.I am trying to create multiple aggregations as a one time activity and then execute them whenever i need them later. 我正在使用RestHeart对MOngoDB聚合查询进行REST调用。我试图一次性创建多个聚合,然后在以后需要时执行它们。 Currently I see that only one aggregation gets created at a time. 目前,我一次只能创建一个聚合。 If I create a new one then it gets overwritten. 如果我创建一个新的,它将被覆盖。

Is it possible to create multiple aggregations as a one time activity with diferent URI? 是否可以使用不同的URI一次性创建多个聚合?

This way, I can call URI later and don't have to rewrite the aggregation queries everytime. 这样,我以后可以调用URI,而不必每次都重写聚合查询。

RESTHeart allows to define aggregations via the aggrs collection property. RESTHeart允许通过aggrs集合属性定义聚合。 See the documentation here https://softinstigate.atlassian.net/wiki/x/AwDw 在此处查看文档https://softinstigate.atlassian.net/wiki/x/AwDw

aggrs is an array of aggregation definitions, something like: aggrs是一组聚合定义,例如:

aggrs: [ { <aggregation_1> }, { <aggregation_2> }, ... ]

an aggregation definition is: 聚合定义为:

{
   "type":"pipeline",
   "uri": <uri>,
       "stages": [
       "<stage_1>",
       "<stage_2>",
       ...
   ]
}

each aggregation is bound to the uri specified in the definition, under the /db/coll/_aggrs , so: 每个聚合都绑定到/db/coll/_aggrs下的定义中指定的uri,因此:

GET /db/coll/_aggrs/aggreation1
GET /db/coll/_aggrs/aggreation2

You say that your aggregation gets overwritten, I suspect that you are updating your collection replacing the aggrs array. 您说您的聚合被覆盖了,我怀疑您是在更新集合以替换aggrs数组。 Make sure to update the collection properties with all your aggregation definitions in the aggrs array 确保使用aggrs数组中的所有聚合定义更新集合属性

So to create a first aggregation using the brilliant httpie cli tool 因此,使用出色的httpie cli工具创建第一个聚合

http PATCH <ip>/db/coll aggrs:='[ {<aggregation_1>} ]'

To create a second aggregation you can either pass whole the aggrs array: 要创建第二个聚合,您可以传递整个aggrs数组:

 http PATCH <ip>/db/coll aggrs:='[ {<aggregation_1>}, {<aggregation_2>} ]'

or add the second one to the aggrs array using the $addToSet update operator 或使用$ addToSet更新运算符将第二个添加到aggrs数组

 http PATCH <ip>/db/coll aggrs:='{"$addToSet": {"aggrs": {<aggregation_2>}}}'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM