Skip to content

Instantly share code, notes, and snippets.

@robertdempsey
Last active March 8, 2020 10:40
Show Gist options
  • Save robertdempsey/9105e57ec1a56e413af91b0008ab71b1 to your computer and use it in GitHub Desktop.
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.
/** 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