aboutsummaryrefslogtreecommitdiff
path: root/db/mongodb.js
diff options
context:
space:
mode:
Diffstat (limited to 'db/mongodb.js')
-rw-r--r--db/mongodb.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/db/mongodb.js b/db/mongodb.js
index 57f1b72..4119c7a 100644
--- a/db/mongodb.js
+++ b/db/mongodb.js
@@ -32,8 +32,24 @@ function setNum(name, num) {
.exec()
}
+function setNumMulti(counters) {
+ const bulkOps = counters.map(obj => {
+ const { name, num } = obj
+ return {
+ updateOne: {
+ filter: { name },
+ update: { name, num },
+ upsert: true
+ }
+ }
+ })
+
+ return Count.bulkWrite(bulkOps, { ordered : false })
+}
+
module.exports = {
getNum,
getAll,
- setNum
+ setNum,
+ setNumMulti
}