mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	retry failed upserts closes #4467
This commit is contained in:
		| @@ -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); | ||||
| 		}); | ||||
| 	}; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user