I have documents in MongoDB, like so:
{
"_id" : ObjectId("5a748c8b178227d602ec9ce8"),
"dateHour" : ISODate("2018-02-02T16:00:00.000Z"),
"data" : [
{
"date" : ISODate("2018-02-02T16:06:35.033Z"),
"cap" : 437105726836.0
},
{
"date" : ISODate("2018-02-02T16:09:25.127Z"),
"cap" : 437316498502.0
},
...
]
}
Using aggregate method (in NodeJS):
db.getCollection('hourly').aggregate([
{$match: {}},
{$unwind: "$data"},
{$project: {_id: 0, date: "$data.date", cap: "$data.cap" } }
])
I get output like:
[
{
"date" : ISODate("2018-02-02T16:06:35.033Z"),
"cap" : 437105726836.0
},
{
"date" : ISODate("2018-02-02T16:09:25.127Z"),
"cap" : 437316498502.0
}
]
QUESTION: What is the most effective way to get output like so:
[
[ISODate("2018-02-02T16:06:35.033Z"), 437105726836.0],
[ISODate("2018-02-02T16:09:25.127Z"), 437316498502.0]
]
?
I can simply add .map(function(item) {return [item.date, item.cap]}) but is this most effective way when working with huge amount of data?