Last active
March 8, 2020 10:40
-
-
Save robertdempsey/9105e57ec1a56e413af91b0008ab71b1 to your computer and use it in GitHub Desktop.
Updates values for properties 'a' and 'b' of System with system_id 123.
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 | |
} | |
*/ | |
system_states_collection.update( | |
{ system_id: 123 }, | |
{ | |
$set: { a: 4 } | |
} | |
) | |
/** | |
Resulting document: | |
{ | |
system_id: 123, | |
a: 4, | |
b: 2, | |
c: 3 | |
} | |
*/ | |
system_states_collection.update( | |
{ system_id: 123 }, | |
{ | |
$set: { b: 5 } | |
} | |
) | |
/** | |
Resulting document: | |
{ | |
system_id: 123, | |
a: 4, | |
b: 5, | |
c: 3 | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment