From 5dc5c80460513fa61ed2a293d464ece60da4c763 Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Fri, 8 May 2020 16:08:17 +0800 Subject: [PATCH] download data record --- src/api/db.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/api/db.js b/src/api/db.js index 765d9ee..d617d55 100644 --- a/src/api/db.js +++ b/src/api/db.js @@ -17,21 +17,26 @@ const db = app.database(); const _ = db.command const counter = db.collection('QRCounter'); -export function insert(value) { - counter.add({ - value: value, - count: 1 - }).then(res => { - console.log(res); - }) -} - export function update(value) { counter.where({ value: _.eq(value) - }).update({ - count: _.inc(1) - }).then(res => { - console.log(res) + }).get().then(res => { + if (res.data.length > 0) { + counter.where({ + value: _.eq(value) + }).update({ + count: _.inc(1) + }).then(res => { + console.log(res) + }) + } + else { + counter.add({ + value: value, + count: 1 + }).then(res => { + console.log(res) + }) + } }) }