mongoose文件没有方法“保存” – 但也是

当迭代由Model.find()返回的一组文档时,我将每个生成的文档传递给另一个函数,最终调用save()方法。 但是我得到这个错误:

 [TypeError: Object #<Object> has no method 'save'] 

我已经确认有问题的对象是一个Mongoose文档。 事实上 – 这真的让我感到困惑。

 console.log(order.save); // { [Function] numAsyncPres: 0 } order.save(); // [TypeError: Object #<Object> has no method 'save'] 

我甚至不明白这是可能的,因为它存在,直到我称之为…

如果需要的话,我会提供更多的上下文代码,但是我越过我的手指,这是我知道的一些已知的奇怪/愚蠢的疏忽,有人会立即认出。

编辑:在审查错误堆栈,我看到它正在调用保存。 否则,我会看到一个完全不同的错误消息。 相反,保存方法无法定位内部保存方法。 这是堆栈:

 at C:\dev\node_modules\mongoose\lib\document.js:1272:13 at Array.forEach (native) at model.pre.err.stack (C:\dev\node_modules\mongoose\lib\document.js:1254:12) at model._next (C:\dev\node_modules\mongoose\node_modules\hooks\hooks.js:50:30) at model.proto.(anonymous function) [as save] (C:\dev\node_modules\mongoose\node_modules\hooks\hooks.js:96:20) at fixNoPriceItem (C:\dev\unimatrix\node_modules\cathy.js:202:10) at Array.forEach (native) at CallManager.callback (C:\dev\unimatrix\node_modules\cathy.js:181:18) at Object.tracker.complete (C:\dev\unimatrix\node_modules\mowse\node_modules\constructors\Call-Manager.js:80:8) at continueHandling (C:\dev\unimatrix\node_modules\mowse\node_modules\constructors\Call-Manager.js:138:14) 

实际调用order.save的函数是fixNoPriceItem ,第六个是down。

保存之前对文档进行的唯一更改如下:

 order.items[targetIndex] = itemData; // items is an arr order.markModified('items'); 

我怀疑这与我如何设置子文档有关