aboutsummaryrefslogtreecommitdiff
path: root/db/mongodb.js
diff options
context:
space:
mode:
Diffstat (limited to 'db/mongodb.js')
-rw-r--r--db/mongodb.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/db/mongodb.js b/db/mongodb.js
new file mode 100644
index 0000000..fa7e96d
--- /dev/null
+++ b/db/mongodb.js
@@ -0,0 +1,36 @@
+'use strict'
+
+const mongoose = require('mongoose')
+const schema = require('./schema')
+
+mongoose.connect(process.env.DB_URL, {
+ useNewUrlParser: true,
+ useUnifiedTopology: true,
+ useFindAndModify: false
+})
+
+const Count = mongoose.connection.model('Count', schema)
+
+function getNum(name) {
+ return Count
+ .findOne({ name }, '-_id -__v')
+ .exec()
+}
+
+function getAll() {
+ return Count
+ .find({ }, '-_id -__v')
+ .exec()
+}
+
+function setNum(name, num) {
+ return Count
+ .findOneAndUpdate({ name }, { name, num }, { upsert: true })
+ .exec()
+}
+
+module.exports = {
+ getNum,
+ getAll,
+ setNum
+} \ No newline at end of file