Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MongoDB aggregation query that returns summarized Basis sleep data for each day
db.sleeps.aggregate( [
{ $unwind : "$content.activities" },
{ $project :
{
"content.activities.date" : 1 ,
"content.activities.sleep" : 1,
"content.activities.start_time" : 1
}
},
{ "$group": {
_id: "$content.activities.date",
start_time : { $min : "$content.activities.start_time.iso"},
offset : { $min : "$content.activities.start_time.time_zone.offset" },
light_minutes : { $sum: "$content.activities.sleep.light_minutes" },
rem_minutes : { $sum: "$content.activities.sleep.rem_minutes" },
deep_minutes : { $sum: "$content.activities.sleep.deep_minutes" },
interruption_minutes : { $sum: "$content.activities.sleep.interruption_minutes" },
unknown_minutes: { $sum: "$content.activities.sleep.unknown_minutes" }
} },
{ $sort: { _id : 1 } },
{ $out: "sleepexport" }
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.