Skip to content

Instantly share code, notes, and snippets.

@johnlpage
Last active February 24, 2022 12:12
Show Gist options
  • Save johnlpage/d248b9511a0724298a9f4136a77b7687 to your computer and use it in GitHub Desktop.
Save johnlpage/d248b9511a0724298a9f4136a77b7687 to your computer and use it in GitHub Desktop.
[{
$match: {
reading: { $gt: 1000, $lt: 40000 }
}
}, {
$setWindowFields: {
partitionBy: "$type",
sortBy: { date: 1 },
output: {
hourago: {
$min: "$reading",
window: {
range: [-3600, 0],
unit: "second"
}
}
}
}
},
{
$set: {
meterdelta: { $subtract: ["$reading", "$hourago"] }
}
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment