1

I am trying to learn to use restHeart rest api and see if I can avoid any custom code to write any java code to query MongoDB.

I am trying to execute below mongoshell query, any idea how should it be written in RestHeart request?

db.getCollection('InsStatData').aggregate({'$match':{'$and':[{ 'sectionName': 'ASSETS'},{'year':2015},{ 'sections.data.rowIdx': 1},{'sections.data.values.colIdx':2}]}},
 { '$unwind': '$sections' },
 { '$unwind': '$sections.data' },
 { '$unwind': '$sections.data.values' },
 {'$match':{'$and':[{ 'sectionName': 'ASSETS'},{'year':2015},{ 
 'sections.data.rowIdx': 1},{'sections.data.values.colIdx':2}]}}
 )

InsStatData is collecitonName.

athenatechie
  • 699
  • 2
  • 8
  • 15

1 Answers1

1

yes RESTHeart supports aggregations.

Basically you can define an aggregation creating a document with the aggregation pipelines in it under /db/coll/_aggrs resource.

The aggregation document has the uri property that makes it available at /db/coll/_aggrs/uri

The aggregation can also have variables in it as {"$var": "n"} and a variable can be passed as follow

GET /db/coll/_aggrs/<uri>=avars={"n": { <any json> }}

Refer to this documentation page for more info https://softinstigate.atlassian.net/wiki/x/AwDw

Andrea Di Cesare
  • 1,125
  • 6
  • 11