Last active
March 8, 2020 10:49
-
-
Save robertdempsey/269be6a2507fb6d18d88a409e7f9f688 to your computer and use it in GitHub Desktop.
Pulls an item from an existing array
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, | |
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