猫鼬:填充与 findById

时间:2021-02-03 15:08:38

标签: mongodb mongoose database-performance

populate 和 findById 在性能上有什么区别?哪个更快?

示例

findById:

const comment = await Comment.findById(commentId);
const user = await User.findById(comment.userId);

填充:

const comment = await Comment.findById(commentId).populate('userId');

0 个答案:

没有答案