Gau*_*av 3 mongoose mongodb node.js mongoose-populate
我知道它的语法及其工作原理,但我无法理解内部工作原理,为什么方法链接一次需要另一种方法,但其他时候不需要?
这段代码工作正常
const cart = await Carts.findById(cartId).populate('product');
Run Code Online (Sandbox Code Playgroud)
但这段代码并没有
let cart = await Carts.findById(cartId);
cart = await cart.populate('product');
Run Code Online (Sandbox Code Playgroud)
为了让它发挥作用,我们使用execPopulate这样的方法。
let cart = await Carts.findById(cartId);
cart = await cart.populate('product').execPopulate();
Run Code Online (Sandbox Code Playgroud)
现在,据我读过 javascript 中的方法链接,代码在没有该execPopulate方法的情况下也应该运行良好。但我似乎无法理解为什么 populate 不适用于现有的猫鼬对象。
Yob*_*Yob 18
对于阅读本文的任何人来说,现在已被删除的注释execPopulate():https ://mongoosejs.com/docs/migration_to_6.html#removed-execpopulate