Merges chronological time-based streams.
The module requires no dependencies, except for running the tests.
npm install stream-combineCombine three time-serie streams, with common document key _id for unix time stamp.
async.map([
"time-series-1"
"time-series-2"
"time-series-3"
], (serie, cb) => {
db.collection(serie, (error, collection) => {
if error return cb error
stream = collection
.find _id: $gt: 12
.sort _id: 1
.stream()
cb(null, stream)
}, (error, streams) => {
(new StreamCombine streams, "_id").pipe someCSVStream
})Or in flowing mode, with example of output object structure:
(new StreamCombine streams, "_id").on("data", data => {
console.log data
// emits objects like
// {
// indexes: [0, 2]
// data: [ { _id: 6, some-data-from-time-series-1 },
// { _id: 6, some-data-from-time-series-3 } ]
// }
// ...
})where:
_idis the common time stamp of the next object in chronological orderindexesis the indexes of the streams that have the current time in commondatais the actual data of the common time step