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

Using the group method on MongoDbMixin #30

Open
sfhorton01 opened this issue Feb 24, 2016 · 3 comments
Open

Using the group method on MongoDbMixin #30

sfhorton01 opened this issue Feb 24, 2016 · 3 comments

Comments

@sfhorton01
Copy link

When using the MongoDbMixin to read data, I need to be able to perform a group or aggregate first. So what I have is something like:

eventsPump.mixin(MongodbMixin(...))
      .useCollection('sites')
      .from(eventsPump.group(['status.description'], {type: 'Master'},
        { sites : 0, transactions: 0 },
        function (curr, result) {
          result.sites++;
          if (curr.metricsSummary) {
            result.transactions += curr.metricsSummary.transactions.count;
          }
        }
      ))
...

However, I am getting an error on the .from line:

Error: Argument must be datapumps.Buffer or stream
    at Pump.module.exports.Pump.from (/web/gstv-server-apps-reports/node_modules/datapumps/lib/Pump.js:94:15)

Am I doing something wrong? Or is this not really supported?

@novaki
Copy link
Member

novaki commented Feb 24, 2016

Unfortunately the .group() method is not wrapped in the pump. A quick workaround could be to call group on mongo collection directly:

eventsPump._mongo.collection.group(<your args here>).stream()

Please note the stream() call after grouping. Input buffers of pumps must be streams, arrays or datapumps Buffers.

@rafaneri
Copy link

rafaneri commented Mar 2, 2017

Is it possible to do the same for aggregation?

eventsPump._mongo.collection.aggregate(<your args here>).stream()

@novaki
Copy link
Member

novaki commented Mar 4, 2017

This should work .aggregate too. But the method will only exist in .from call if the mixin receives a mongodb connection, not a connection string.

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

3 participants