Closed afolaran closed 8 years ago
first try to remove the \
second, from the documentation:
Note that the dollar prefixed operators in stages must be underscore escaped, e.g. "_$exits"
so it should be (I haven't tested it)
aggrs:='[ {"type":"pipeline", "uri":"total-by-item", "stages": [ {"_$match": { "Item": { "_$var": "Item"}}}, {"_$group": { "_id": "$Item", "total": {"_$sum": "$Amount"}}}]}]'
Hello Andrea. I tried it and it still returns the same error.
"http status code": 406, "http status description": "Not Acceptable", "message": "Invalid JSON"
I think you should try it also and see if it works cos now I am stuck and cannot make progress with my project work because of this. I need to successfully make an aggregation query using a REST client. I believe the problem is still with the syntax. I look forward to your response. Thanks.
Hello @afolaran
I just tried it and it works for me!
This is what I have done (I used httpie; actually the aggrs:= syntax is specific of this client)
you might want to updated httpie and check what it is actually sending specifying the -v option.
1. create the collection with the definition of the aggregation
$ http PUT 127.0.0.1:8080/test/issue101 aggrs:='[ {"type":"pipeline", "uri":"total-by-item", "stages": [ {"_$match": { "Item": { "_$var": "Item"}}}, {"_$group": { "_id": "$Item", "total": {"_$sum": "$Amount"}}}]}]'
HTTP/1.1 200 OK
...
2. create some data
$ http POST 127.0.0.1:8080/test/issue101 Item=a Amount:=10
HTTP/1.1 201 Created
...
$ http POST 127.0.0.1:8080/test/issue101 Item=a Amount:=20
HTTP/1.1 201 Created
...
$ http POST 127.0.0.1:8080/test/issue101 Item=a Amount:=30
HTTP/1.1 201 Created
...
3. test the aggregation
$ http GET 127.0.0.1:8080/test/issue101/_aggrs/total-by-item?avars='{"Item":"a"}'
HTTP/1.1 200 OK
...
{
"_embedded": {
"rh:result": [
{
"_id": "a",
"total": 60
}
]
},
"_returned": 1,
"_size": 1,
"_total_pages": 1
}
Working!
Hello Andrea. I am afraid I am still facing some problems. I have installed httpie and I have successfully queried some collections in the database on my local machine. However, I still cannot carry out aggregation request. Below I provide a screenshot of the error message I got.
hi @afolaran
I suggest you to write the json in a file, check the syntax and run
http -a a:a PUT 127.0.0.1:8080/db/coll < file.json
hope this is supported in windows!
Hello.
I am having problems running an aggregate query with restheart using a REST client. The documentation does not seem to be clear enough for me on this. I have created a test database and collection just to see how it works. I select PUT/POST as my HTTP method and then insert
aggrs:='[\ {"type":"pipeline",\ "uri":"total-by-item",\ "stages": [\ {"$match": { "Item": { "$var": "Item"}}},\ {"_$group": { "id": "$Item", "total": {"$sum": "$Amount"}}}]}]'
in the body section to create the aggrs metadata but it does not work at all. It returns the following error message;
"http status code": 406, "http status description": "Not Acceptable", "message": "Invalid JSON",
I have tried to adjust the syntax in different ways but I keep getting error messages. I know the problem is in my declaration of the metadata. Please kindly make available to me the proper syntax for carrying out the aggregation operation as well syntax for even inserting documents into a collection using a REST client.
I look forward to your response. Thanks