Created
August 22, 2013 06:30
-
-
Save jmosbech/6303849 to your computer and use it in GitHub Desktop.
attempt to emulate the missing support for mongo array upserts
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
// 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