Skip to content

Instantly share code, notes, and snippets.

@pdewouters
Last active April 27, 2016 16:01
Show Gist options
  • Save pdewouters/e797d028cbc5cf14d71afe9db6ac8a66 to your computer and use it in GitHub Desktop.
Save pdewouters/e797d028cbc5cf14d71afe9db6ac8a66 to your computer and use it in GitHub Desktop.
Ensure array property value is unique when updating a doc
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