I am giving MongoDB a shot and building a simple journal with MongoDB and PYTHON. I have this simple structure :
db.posts.findOne()
{
"waketime": ISODate("2016-03-18T11:20:00Z"),
"bedtime": ISODate("2016-03-18T22:00:00Z"),
"day": "day entry",
"dream": "dream entry",
"workout" : [{"type":"cardio"},{"time":45}],
"meditation" : [{"time":10},{"time":10}],
"sex": "none"
}
I am trying to get the time I spent working out and the time I spent working out per type of workout. For the last I have gotten to this :
cursor = db.posts.aggregate([
{"$group": {"_id" : "$workout.type", "count": {"$sum": "$workout.time"}}}
])
it returns this :
{u'count': 0, u'_id': [u'cardio']}
{u'count': 0, u'_id': [u'strength']}
it seems to have grouped correctly on workout.type but it doesn't $sum workout.time
anyone can help me?
thank you