1. router.get('/product/:name', controller.product.product.index);
    2. async find(m) {
    3. const db = this.app.mongodb;
    4. const res = await db.collection(m).find().toArray();
    5. return res;
    6. }
    7. for (var i = 0; i < tables.length; i++) {
    8. await db.collection(tables[i]).updateOne({ _id: ObjectId(id) }, { $set: { isShow: isShow, actives: actives } });
    9. var res = await db.collection(tables[i]).find({ _id: ObjectId(id) }).toArray();
    10. if (res.length) {
    11. try {
    12. if (isShow) {
    13. await db.collection('user').insertOne(res[0])
    14. ctx.body = {
    15. status: 200,
    16. msg: "收藏成功"
    17. }
    18. } else {
    19. await db.collection('user').deleteOne({ _id: ObjectId(id) })
    20. ctx.body = {
    21. status: 200,
    22. msg: "取消收藏"
    23. }
    24. }
    25. } catch (err) {
    26. this.app.logger.error(err);
    27. ctx.body = {
    28. status: 400,
    29. msg: "数据库中数据已经存在,请不要重复添加"
    30. }
    31. }
    32. }
    1. const {ctx}=this
    2. var {id,actives} = ctx.request.body;
    3. const db = this.app.mongodb;
    4. actives=Number(actives)
    5. var res = await db.collection('user').find({ _id: ObjectId(id)}).toArray();
    6. console.log(res[0].actives);
    7. if(actives!=res[0].actives){
    8. res[0].actives=actives
    9. db.collection('user').update({ _id: ObjectId(id) },{$set:{actives}})
    10. ctx.body={
    11. code:200
    12. }
    13. }