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

Mongoose query aggregation #212

Closed
Aranad opened this issue Sep 6, 2017 · 12 comments
Closed

Mongoose query aggregation #212

Aranad opened this issue Sep 6, 2017 · 12 comments

Comments

@Aranad
Copy link

Aranad commented Sep 6, 2017

Is there any way to use the Mongo/Mongoose collection aggregation-pipline from feathers-mongoose?

@jamesjnadeau
Copy link
Contributor

I don't think there is, as it strays too far from the "unified query system"(or whatever it's called, please correct me),

You could extend/override the find/_find functions to customize this to your will though.

@corymsmith
Copy link
Contributor

@Aranad I've created custom services that use aggregation underneath. Or if you need an aggregation in addition to other data from a service you could add an after hook that does the aggregation as well.

@Aranad
Copy link
Author

Aranad commented Sep 6, 2017

@corymsmith that sounds awesome... could you point me in the right direction to read up on and implement that, thanks! :-)

@subodhpareek18
Copy link

maybe try putting the params in params.mongoose

@corymsmith
Copy link
Contributor

@Aranad Theres some info here on creating a custom service, unfortunately my custom service is proprietary so I can't share it: https://docs.feathersjs.com/api/services.html

@Aranad
Copy link
Author

Aranad commented Sep 7, 2017

I figured out a way to do it from the before.find hook. hook.service.Model is the mongoose model object that has aggregate() available, so I made a convention for passing aggregate data in find() which the hook can detect and divert to the aggregate method :-)

@corymsmith
Copy link
Contributor

Perfect!

@daffl
Copy link
Member

daffl commented Sep 11, 2017

Glad it worked! Closing this one then.

@daffl daffl closed this as completed Sep 11, 2017
@stalinb87
Copy link
Contributor

@Aranad how exactly do you accomplish this, do you have some example?

@Aranad
Copy link
Author

Aranad commented Oct 23, 2017

@stalinb87 yes I documented how I did it here: https://www.organicdesign.co.nz/Our_SPA#Database_schemas_and_querying, a similar method could also be done with the hook creating the complex query server-side instead of the whole aggregation query structure being passed from client to server.

@MacgyverMartins
Copy link

You can override context.params.query at before.find hook whit the mongoose query

@priyabagus
Copy link

Example aggregate for users

await app.service('users').Model.aggregate( [ { <stage1> }, { <stage2> } ... ] )

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

No branches or pull requests

8 participants