Since the programmers of the clients that use this web service are too lazy to learn the JSON semantics of the MongoDB aggregation framework, I have created a simple "human-friendly" language that does not add any extra functionality to the existing MongoDB's JSON format.
The first early version is here: https://github.com/mariomac/
It basically translates a query like this:
FROM docs
MATCH obj.prop > 3
GROUP BY val1
sum(val1) AS Field1
sum(obj.prop) AS Field2
sum(obj.prop + val1) AS FieldsSum
SORT BY FieldsSum DESCENDING
Into something like this:
db.docs.aggregate([
{ "$match" : { "obj.prop" : { "$gt" : 3}}} ,
{ "$group" : { "_id" : "$val1" ,
"Field1" : { "$sum" : "$val1"} ,
"Field2" : { "$sum" : "$obj.prop"} ,
"FieldsSum" : { "$sum" : { "$add" : [ "$obj.prop" , "$val1"]}}}} ,
{ "$sort" : { "FieldsSum" : -1}}
]);
In its current status, MongoAL fulfills the requirements of my web service, but if I notice some interest from somebody to use it, I would like to continue developing it and adding some extra functionalities, such as:
- Porting it to Javascript (now it's in Java because my WS is java)
- Supporting the complete MongoDB aggregation pipeline (now only supports $match, $group and $sort operations.
- Adding an "FORMAT AS" command to format the output to, for example, XML, JSON, CSV...
Do you think this can be interesting for your applications such as, e.g. exposing the MongoDB aggregation capabilities to external clients?
Any suggestion and comment will be very appreciated :-)
Thanks for reading this!
One could say this is to Mongo's aggregation commands as CoffeeScript is to JavaScript? Looks good at any rate.
댓글 없음:
댓글 쓰기