Last active
April 27, 2016 16:01
-
-
Save pdewouters/e797d028cbc5cf14d71afe9db6ac8a66 to your computer and use it in GitHub Desktop.
Ensure array property value is unique when updating a doc
This file contains hidden or 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
Venue.findOneAndUpdate( | |
{venue: venueParam}, | |
{$addToSet: {going: req.user.email}}, // $addToSet will only add if not already existing | |
{safe: true, upsert: true}, | |
function(err, existingVenue){ | |
if(err) return err | |
res.json(existingVenue) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment