fluent aggregate query builder with promise and streaming support
A wrapper around MongoDB's
- Returns a proper stream
- Easier pipeline building
- Return promises
This is based on maggregate which is not up to date with MongoDB 2.6+ and friends.
var aggregate = require'aggregate-stream';// return all the results at onceaggregatecollectionmatch'identity': 'person'group_id: '$_id'count:$sum: 1toArray// as a promiseaggregatecollection// pipeline...then// as a streamhttpcreateServerressetHeader'content-type' 'application/json'aggregatecollection// pipeline...pipeJSONStreamstringifypiperes
Return a new aggregation instance with options. See options: http://mongodb.github.io/node-mongodb-native/api-generated/collection.html#aggregate
Set an option after initialization.
Manipulate each document before returning them.
aggregatecollectiontransformdoctransformed = true;return doc
Each operator is its own method. See: http://docs.mongodb.org/manual/meta/aggregation-quick-reference/#aggregation-operator-quick-reference
Return all the results as a single array. If no callback is supplied, a promise is returned.
Return the "explain" on the query. If no callback is supplied, a promise is returned.
Destroy the stream. Use this to prevent any leaks.
httpcreateServervar stream = aggregatecollectionreqsocketonce'close'// always make sure this cursor is closed when the request is finishedstreamdestroy
A wrapper around
.toArray() that can be implicitly called by a control flow engine.
covar docs = yield aggregatecollectionmatchgroup // ...
This makes each instance a "promise",
but you shouldn't be using
.then() directly - use