Problems with Mongoose updating ref and populate ref

Environment:

  • Mongodb 3.6.3
  • mongoose: 5.2.5
  • nodeJS: 8.x

description:

  • simulate the blog system. There are two collection (articles / comments), schema as follows
// Query for comment
// Params: { offset / limit / sortBy }
exports.getComments = function(req, res) {
  let count;
  let data;
  let { offset, limit, sortBy } = req.query;
  let { aid } = req.params

  // Get Total count
  Comment.estimatedDocumentCount(function(err, num) {
    if (err) {
      errCallback(err, res);
      return
    }
    count = num;
  });
  offset = Number(offset);
  limit = Number(limit);
  console.log("aid", aid);
  Article.findById(aid).
  populate("comments").
  // skip(offset).
  // limit(limit).
  // sort(dueSortby(sortBy)).
  exec((err, comment) => {
    console.log("execed!", comment)
    data = comment;
    getCountCallback(data, count, res);
  });
}

long-winded, I am afraid to lose the details, if there is any solution, please do not hesitate to let me know!

Apr.29,2021
Menu