|
|
|
@ -524,6 +524,13 @@ module.exports = function(db, module) {
|
|
|
|
|
data.score = parseInt(increment, 10);
|
|
|
|
|
|
|
|
|
|
db.collection('objects').findAndModify({_key: key, value: value}, {}, {$inc: data}, {new: true, upsert: true}, function(err, result) {
|
|
|
|
|
// if there is duplicate key error retry the upsert
|
|
|
|
|
// https://github.com/NodeBB/NodeBB/issues/4467
|
|
|
|
|
// https://jira.mongodb.org/browse/SERVER-14322
|
|
|
|
|
// https://docs.mongodb.org/manual/reference/command/findAndModify/#upsert-and-unique-index
|
|
|
|
|
if (err && err.message.startsWith('E11000 duplicate key error')) {
|
|
|
|
|
return module.sortedSetIncrBy(key, increment, value, callback);
|
|
|
|
|
}
|
|
|
|
|
callback(err, result && result.value ? result.value.score : null);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|