From fea9c8962021fed6bf8f67c2b4d54cc30692bd8b Mon Sep 17 00:00:00 2001 From: alwxkxk Date: Wed, 8 Nov 2023 20:51:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20id=E4=BD=BF=E7=94=A8=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo2/myapp/bin/mongodb.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/demo2/myapp/bin/mongodb.js b/demo2/myapp/bin/mongodb.js index 17600d3..bce97ad 100644 --- a/demo2/myapp/bin/mongodb.js +++ b/demo2/myapp/bin/mongodb.js @@ -14,20 +14,22 @@ let mongodb ={ mongodb.insert = function(data,callback) { //添加插入时间 data.createdAt= new Date() - if(!dataObj[data.id]){ - dataObj[data.id] = [] + const id = String(data.id) + if(!dataObj[id]){ + dataObj[id] = [] } - dataObj[data.id].push(data) + dataObj[id].push(data) // 超过10个的数据删除 - if(dataObj[data.id].length>10){ - dataObj[data.id].shift() + if(dataObj[id].length>10){ + dataObj[id].shift() } } // 查找数据 mongodb.find=function (data,callback) { - callback(null,dataObj[data.id] || []); + const id = String(data.id) + callback(null,dataObj[id] || []); }