router.get('/product/:name', controller.product.product.index); async find(m) { const db = this.app.mongodb; const res = await db.collection(m).find().toArray(); return res; } for (var i = 0; i < tables.length; i++) { await db.collection(tables[i]).updateOne({ _id: ObjectId(id) }, { $set: { isShow: isShow, actives: actives } }); var res = await db.collection(tables[i]).find({ _id: ObjectId(id) }).toArray(); if (res.length) { try { if (isShow) { await db.collection('user').insertOne(res[0]) ctx.body = { status: 200, msg: "收藏成功" } } else { await db.collection('user').deleteOne({ _id: ObjectId(id) }) ctx.body = { status: 200, msg: "取消收藏" } } } catch (err) { this.app.logger.error(err); ctx.body = { status: 400, msg: "数据库中数据已经存在,请不要重复添加" } } }
const {ctx}=this var {id,actives} = ctx.request.body; const db = this.app.mongodb; actives=Number(actives) var res = await db.collection('user').find({ _id: ObjectId(id)}).toArray(); console.log(res[0].actives); if(actives!=res[0].actives){ res[0].actives=actives db.collection('user').update({ _id: ObjectId(id) },{$set:{actives}}) ctx.body={ code:200 } }