mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 18:56:15 +01:00
fix decr/incrObjectField if key in array doesn't exist create it
This commit is contained in:
@@ -289,7 +289,10 @@ module.exports = function (db, module) {
|
||||
|
||||
if (Array.isArray(key)) {
|
||||
var bulk = db.collection('objects').initializeUnorderedBulkOp();
|
||||
bulk.find({ _key: { $in: key } }).upsert().update({ $inc: data });
|
||||
key.forEach(function (key) {
|
||||
bulk.find({ _key: key }).upsert().update({ $inc: data });
|
||||
});
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
bulk.execute(function (err) {
|
||||
|
||||
@@ -408,10 +408,11 @@ describe('Hash methods', function () {
|
||||
});
|
||||
|
||||
it('should decrement multiple objects field by 1 and return an array of new values', function (done) {
|
||||
db.decrObjectField(['testObject13', 'testObject14'], 'age', function (err, data) {
|
||||
db.decrObjectField(['testObject13', 'testObject14', 'decrTestObject'], 'age', function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data[0], 97);
|
||||
assert.equal(data[1], -1);
|
||||
assert.equal(data[2], -1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user