When iterating over a set of documents returned by Model.find(), I pass each resulting document into another function that eventually calls the save() method. But I get this error:
[TypeError: Object #<Object> has no method 'save']
I've confirmed that the object in question is a Mongoose document. In fact -- and this is what really has me baffled...
console.log(order.save); // { [Function] numAsyncPres: 0 }
order.save(); // [TypeError: Object #<Object> has no method 'save']
I can't even understand how that's possible, for it to exist until I call it...
I'll provide more code for context if needed, but I'm crossing my fingers that this is some known oddness / stupid oversight on my part that someone will immediately be able to recognize.
Edit: On reviewing the error stack, I see that it is calling save. Otherwise, I'd be seeing an entirely different error message. Rather, the save method is failing to locate an internal save method. Here's the stack:
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)
The function which actually calls order.save is fixNoPriceItem, the sixth one down.
The only alterations made to the document before save are the following:
order.items[targetIndex] = itemData; // items is an arr
order.markModified('items');
I suspect it's related to how I'm setting the subdocument...