Selene
0
Q:

how to delete popultate subdocument mongoose

Surf
    .find({user_id: {$in: userIds}})
    .populate('user_id', 'name boards') // added boards
    .populate('friends', 'name')
    // .populate('board_id', 'name size') // can't do this as discussed
    .exec(function (err, surfs) {
      if (err) {
        return handleError(res, err);
      }

      surfs.forEach(function (surf) {
        surf.set('boardInfo', surf.user_id.boards.id(surf.board_id), {strict: false});
      });
      // TODO: now remove the surf.user_id.boards.
      return res.json(200, surfs);
    });
0
exports.feed = function (req, res) {
  var userIds = req.user.friends;

  Surf
    .find({user_id: {$in: userIds}})
    .populate('user_id', 'name boards') // added boards
    .populate('friends', 'name')
    // .populate('board_id', 'name size') // can't do this as discussed
    .exec(function (err, surfs) {
      if (err) {
        return handleError(res, err);
      }

      surfs.forEach(function (surf) {
        surf.boardInfo = surf.user_id.boards.id(surf.board_id)
      });
      // TODO: now remove the surf.user_id.boards.
      return res.json(200, surfs);
    });

};
0

New to Communities?

Join the community