Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for a AggregateDocument function #6

Open
rodrigomurta opened this issue Jan 14, 2016 · 2 comments
Open

Suggestion for a AggregateDocument function #6

rodrigomurta opened this issue Jan 14, 2016 · 2 comments

Comments

@rodrigomurta
Copy link
Contributor

Hi Zach,
Do you have plans to create a AggregateDocument function?
It would be really cool if I could do things like:

AggregateDocument[ myColletion
        ,{"$project" ->  {"author" -> 1}}
        ,{"$group" -> {"_id" -> "$author", "count" -> {"$sum" -> 1}}}
        ,{"$sort" -> {"count" -> -1}}
        ,{"$limit" -> 5}
]

tks
Murta

@zbjornson
Copy link
Owner

Hadn't gotten that far, but yes, thanks for the suggestion. I'll play with some designs soon.

(If you need that functionality immediately, you can access the the underlying java object for the collection with collection["collection"] and use jlink to call the aggregation commands that you need.)

Semi-related, I keep forgetting to add Sort options to all the query functions (just made #7 for that).

@zbjornson
Copy link
Owner

Feedback from Mike H on syntax:

Change the OP example to a list of stages:

AggregateDocuments[ myColletion,{
        ,{"$project" ->  {"author" -> 1}}
        ,{"$group" -> {"_id" -> "$author", "count" -> {"$sum" -> 1}}}
        ,{"$sort" -> {"count" -> -1}}
        ,{"$limit" -> 5}
        }
]

or more generally AggregateDocuments[ myColletion, myPipeline], where myPipeline is a list containing one or more pipeline steps which are lists. Each pipeline stage takes the form {$operator -> operand} where the operand is normally a list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants