From a8f8b387807d68d1397144794d27d00d7faf06ae Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 21 Aug 2015 03:50:00 +0000 Subject: [PATCH] aggregate trades by timestamp --- collect-data/queries.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 collect-data/queries.js diff --git a/collect-data/queries.js b/collect-data/queries.js new file mode 100644 index 0000000..ad7ce09 --- /dev/null +++ b/collect-data/queries.js @@ -0,0 +1,12 @@ +db.ltc_trades.aggregate([ + { $group: { + _id: '$timestamp', + total_price: { $sum: { $multiply: [ "$price", "$amount" ] } }, + total_quantity: { $sum: "$amount" } + } }, + { $project: { + price: { $divide: [ "$total_price", "$total_quantity" ] }, + amount: "$total_quantity" + } }, + { $sort: {_id: 1} } +])