mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 02:36:16 +01:00
changes to leaveAllGroups
Groups.destroy can take an array of groupnames Groups.leave can take an array of groupnames db.incrObjectField/decrObjectField can take an array of keys db.sortedSetRemove can take an array of keys and values db.setRemove can take an array of keys
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var pubsub = require('../../pubsub');
|
||||
|
||||
module.exports = function (db, module) {
|
||||
@@ -286,6 +287,33 @@ module.exports = function (db, module) {
|
||||
field = helpers.fieldToString(field);
|
||||
data[field] = value;
|
||||
|
||||
if (Array.isArray(key)) {
|
||||
var bulk = db.collection('objects').initializeUnorderedBulkOp();
|
||||
bulk.find({ _key: { $in: key } }).upsert().update({ $inc: data });
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
bulk.execute(function (err) {
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
function (next) {
|
||||
key.forEach(function (key) {
|
||||
module.delObjectCache(key);
|
||||
});
|
||||
|
||||
module.getObjectsFields(key, [field], next);
|
||||
},
|
||||
function (data, next) {
|
||||
data = data.map(function (data) {
|
||||
return data && data[field];
|
||||
});
|
||||
next(null, data);
|
||||
},
|
||||
], callback);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
db.collection('objects').findAndModify({ _key: key }, {}, { $inc: data }, { new: true, upsert: true }, function (err, result) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
|
||||
Reference in New Issue
Block a user