Node.js 在mongoose中记录用户活动并给出建议

Node.js 在mongoose中记录用户活动并给出建议,node.js,mongoose,nosql,recommendation-engine,Node.js,Mongoose,Nosql,Recommendation Engine,我正在使用基于协同过滤的推荐引擎库。Node.js通过Mongoose使用MongoDB实现。自述文件似乎对如何使用该库很直接。但问题是我不知道如何将它与我的查询相结合。从他们的自述 The most fundamental use case of logging user activity, running the engine, and retrieving recommendations for a user is achieved via: akin.activity.log(user

我正在使用基于协同过滤的推荐引擎库。Node.js通过Mongoose使用MongoDB实现。自述文件似乎对如何使用该库很直接。但问题是我不知道如何将它与我的查询相结合。从他们的自述

The most fundamental use case of logging user activity, running the engine, and retrieving recommendations for a user is achieved via:

akin.activity.log(userId, itemId, { type: 'itemType' }, 'action');
...
akin.run();
...
akin.recommendation.getAllRecommendationsForUser(userId);
因此,在我的代码中,我有一个与项有一对多关系的用户。 并应插入类似的活动。。在我的疑问中?我是否需要重写查询以查找userId,ItemId

/ create a quote
const quoteCreate = (req, res) => {
//akin.activity.log(userId, itemId, { type: 'itemType' }, 'action');
  console.log(req.body);
  User.findById(req.userId, function (err, found) {
    if (err) {
      console.log("err");
    } else if (!found) {
    } else {
      console.log(found);
      const quote = new Quote({
        title: req.body.title,
        text: req.body.text,
        quoteType: req.body.quoteType,
      });
      quote
        .save()
        .then((quote) => {
          User.updateOne(
            { _id: req.userId },
            { $push: { quotes: quote._id } },
            (err) => {
              res.send(quote);
            }
          );
        })
        .catch((err) => {
          console.log(err);
        });
    }
  });
};
获得单一报价

const quoteAll = (req, res) => {
akin.activity.log(userId, itemId, { type: 'itemType' }, 'action');
  Quote.find()
    .then((result) => {
      res.send(result);
    })
    .catch((err) => {
      console.log(err);
    });
};

检查用户是否已登录

verifyToken = (req, res, next) => {

  let token = req.headers["x-access-token"];
//akin.activity.log(userId, itemId, { type: 'itemType' }, 'action');
  if (!token) {
    return res.status(403).send({ message: "No token provided!" });
  }

  jwt.verify(token, config.secret, (err, decoded) => {
    if (err) {
      return res.status(401).send({ message: "Unauthorized!" });
    }
    req.userId = decoded.id;
    next();
  });
};
链接: