Last active
March 11, 2020 09:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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