I have 1 min OHLC bars on some market data that I imported into Mongo DB.
Each document looks like this:
{
"_id" : ObjectId("5ac3163f31a0632c7642ca1c"),
"Date" : "08/06/2007",
"Time" : "15:01",
"Open" : 1310,
"High" : 1310.25,
"Low" : 1309.5,
"Close" : 1310,
"Up" : 209,
"Down" : 165,
"Volume" : 0
}
I want to build a function that allows me to quickly generate X-bar intervals from this data. i.e. generate output 5-min bars, 1 hr bars, daily bars, etc... I also want to be able to filter out a data range.
I've been playing around with Mongo's aggregation functions, but I'm getting overwhelmed how I should approach this AND how I should order the pipeline operations.
Do I first group by 'Date', then sort by 'Time', then group again by $first, $last, $max and $min?
Or do I first create a new field somehow combining 'Date' and 'Time' and then proceed to the grouping?
Although don't I need to first somehow convert the "Date" and "Time" fields from string to Date field so that Mongo knows how to sort and match properly? ...but then which order would I do that in?
I'm still a newbie to MongoDB, so any advice would be appreciated.