I recently upgraded an old project to Mongoose 4.5.10 and I've started getting the "Mongoose: Query.prototype.stream() is deprecated in mongoose >= 4.5.0, use Query.prototype.cursor() instead" warnings.
If I directly replace cursor in the above I get a huge stack trace which I cannot make head or tail of:
TypeError: first argument must be a string or Buffer
at ServerResponse.OutgoingMessage.write (_http_outgoing.js:447:11)
at QueryCursor.ondata (_stream_readable.js:542:20)
at emitOne (events.js:77:13)
at QueryCursor.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:153:18)
at QueryCursor.Readable.push (_stream_readable.js:111:10)
at [node_modules_path]/mongoose/lib/querycursor.js:70:11
at [node_modules_path]/mongoose/lib/querycursor.js:258:5
at model.Document.init ([node_modules_path]/mongoose/lib/document.js:296:5)
at _create ([node_modules_path]/mongoose/lib/querycursor.js:254:12)
at [node_modules_path]/mongoose/lib/querycursor.js:219:17
at handleCallback ([node_modules_path]/mongoose/node_modules/mongodb/lib/utils.js:96:12)
at [node_modules_path]/mongoose/node_modules/mongodb/lib/cursor.js:661:5
at handleCallback ([node_modules_path]/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:159:5)
at nextFunction ([node_modules_path]/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:683:5)
at [node_modules_path]/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:585:7
at queryCallback ([node_modules_path]/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:241:5)
at Callbacks.emit ([node_modules_path]/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:119:3)
at null.messageHandler ([node_modules_path]/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:358:23)
at Socket.<anonymous> ([node_modules_path]/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:211:18)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
I was wondering what the new form of the call should be once query.stream() disappears? I've not managed to find any suggestions other than using a combination of lean and exec. Most suggestions seem to suggest the old form using stream.