Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save robertdempsey/0146246ca657e081a2801f289f91380f to your computer and use it in GitHub Desktop.
Save robertdempsey/0146246ca657e081a2801f289f91380f to your computer and use it in GitHub Desktop.
Sets the value of 'a' to 4, but also stores the timestamp from the source for when the notification was published
/** create connection pool to system DB in MongoDB
* assume we are using https://www.npmjs.com/package/mongodb
* assume we begin with:
{
system_id: 123,
a: 1,
b: 2,
c: 3
}
Receive new state with the following data:
{
system_id: 123,
a: 4,
published: '2020-03-10T10:33:43.012Z'
}
*/
system_states_collection.update(
{ system_id: 123 },
{
$set: {
a: 4,
'last_modified.a': Date('2020-03-10T10:33:43.012Z')
},
}
)
/**
Resulting document:
{
system_id: 123,
a: 4,
b: 2,
c: 3,
last_modified: {
a: '2020-03-10T10:33:43.012Z'
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment