Skip to content

Instantly share code, notes, and snippets.

@robertdempsey
Last active March 8, 2020 10:49
Show Gist options
  • Save robertdempsey/269be6a2507fb6d18d88a409e7f9f688 to your computer and use it in GitHub Desktop.
Save robertdempsey/269be6a2507fb6d18d88a409e7f9f688 to your computer and use it in GitHub Desktop.
Pulls an item from an existing array
/** 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,
watcher_emails: ['somebody@emailaddress.com']
}
*/
system_states_collection.update(
{ system_id: 123 },
{
$pull: {
watcher_emails: 'somebody@emailaddress.com'
}
}
)
/**
Resulting document:
{
system_id: 123,
a: 4,
b: 5,
c: 3,
watcher_emails: []
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment