Skip to content

Instantly share code, notes, and snippets.

@jmosbech
Created August 22, 2013 06:30
Show Gist options
  • Save jmosbech/6303849 to your computer and use it in GitHub Desktop.
Save jmosbech/6303849 to your computer and use it in GitHub Desktop.
attempt to emulate the missing support for mongo array upserts
// mongo array upsert
mongo('settings').update({'authorizations._id': {$ne: app._id}}, {$push: {'authorizations': app}}, {safe: true, 'new': true}, function(err, newSettings){
if (err) {
return callback(err);
}
if (!newSettings) {
return mongo('settings').update({'authorizations._id': app._id}, {$set: {'authorizations.$': app}}, {safe: true}, callback);
}
callback();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment