I am on MongoDB 2.6.0, and I have a collection with documents like this:
{ "mid" : 1021,
"day" : 298,
"data":[
{"ts" : 1,"kwh" : 0.017},
{"ts" : 2,"kwh" : 0.018},
{"ts" : 3,"kwh" : 0.019},
... ] }
I would like to flatten the array elements into individual fields like this:
{ "mid" : 1021,
"day" : 298,
"ts1" : 0.017,
"ts2" : 0.018,
"ts3" : 0.019,
...
}
This looks like it should be possible with the Aggregation framework, but I really can't figure out how to re-project the data array's "kwh" elements based on the value of "ts".
Anybody know how to do this?
Thanks for any help!