gridfs-stream icon indicating copy to clipboard operation
gridfs-stream copied to clipboard

Replace Cursor.nextObject because it was removed from node-mongodb-native library

Open HolgerFrank opened this issue 7 years ago • 9 comments

Cursor.nextObject was deprecated since version 2 of the node-mongodb-native library and was now removed completely from the library. Because gridfs-stream uses Cursor.nextObject it is not compatible any more with the new version which is used from mongoose 5 now. Cursor.nextObject must be replaced by Cursor.next

https://github.com/mongodb/node-mongodb-native/blob/3.0.0/CHANGES_3.0.0.md https://github.com/mongodb/node-mongodb-native/pull/1527

HolgerFrank avatar Feb 01 '18 15:02 HolgerFrank

I am experiencing the same issue right now after updating to mongoose 5. Running MongoDB 3.6.3 and gridfs-stream 1.1.1.

0|server   | TypeError: cursor.nextObject is not a function
0|server   |     at /srv/api/node_modules/gridfs-stream/lib/index.js:143:12
0|server   |     at handleCallback (/srv/api/node_modules/mongodb/lib/utils.js:128:55)
0|server   |     at Collection.find (/srv/api/node_modules/mongodb/lib/collection.js:376:12)
0|server   |     at Grid.findOne (/srv/api/node_modules/gridfs-stream/lib/index.js:140:14)
0|server   |     at Server.getImage (/srv/api/app/controllers/static.js:30:9)
0|server   |     at next (/srv/api/node_modules/restify/lib/server.js:992:30)
0|server   |     at f (/srv/api/node_modules/once/once.js:36:25)
0|server   |     at Server.parseBody (/srv/api/node_modules/restify-plugins/lib/plugins/bodyParser.js:58:17)
0|server   |     at next (/srv/api/node_modules/restify/lib/server.js:992:30)
0|server   |     at f (/srv/api/node_modules/once/once.js:36:25)
0|server   |     at Server.readBody (/srv/api/node_modules/restify-plugins/lib/plugins/bodyReader.js:81:13)
0|server   |     at next (/srv/api/node_modules/restify/lib/server.js:992:30)
0|server   |     at f (/srv/api/node_modules/once/once.js:36:25)
0|server   |     at Server.gzip (/srv/api/node_modules/restify-plugins/lib/plugins/gzip.js:60:9)
0|server   |     at next (/srv/api/node_modules/restify/lib/server.js:992:30)
0|server   |     at f (/srv/api/node_modules/once/once.js:36:25)
0|server   |     at Server.parseQueryString (/srv/api/node_modules/restify-plugins/lib/plugins/query.js:28:20)
0|server   |     at next (/srv/api/node_modules/restify/lib/server.js:992:30)
0|server   |     at f (/srv/api/node_modules/once/once.js:36:25)
0|server   |     at Server.parseDate (/srv/api/node_modules/restify-plugins/lib/plugins/date.js:40:21)
0|server   |     at next (/srv/api/node_modules/restify/lib/server.js:992:30)
0|server   |     at f (/srv/api/node_modules/once/once.js:36:25)

lobermann avatar Mar 07 '18 23:03 lobermann

You could monkey patch it until its fixed (with evil eval 😉):

const Grid = require('gridfs-stream');
eval(`Grid.prototype.findOne = ${Grid.prototype.findOne.toString().replace('nextObject', 'next')}`);

Schinkentanz avatar Mar 27 '18 08:03 Schinkentanz

Another option is to change in the source at Grid.prototype.findOne:

cursor.nextObject(callback);

to:

cursor.next(callback);

This way you will don't need remember to update your code. I think. =)

wendellpereira avatar Apr 11 '18 14:04 wendellpereira

Can confirm! This is still happening! Wendellpereira has the right answer to this issue.

Fixed by changing ../node_modules/gridfs-stream/lib/index.js line 143 cursor.nextObject(callback); to cursor.next(callback);

Wisedemic avatar Apr 27 '18 02:04 Wisedemic

#133 will help

lykmapipo avatar May 13 '18 11:05 lykmapipo

Is it possible fix the package for not use monkey patch. this issue is from last year and out of date

xelaz avatar Aug 17 '20 13:08 xelaz

cursor.next is not a function is the new error i am getting after changing nextObject to next

cmouli96 avatar Nov 08 '20 05:11 cmouli96

Has this been resolved ?

traoremp avatar Mar 30 '21 00:03 traoremp

@traoremp from what I see this project is no longer maintained. I switched to @lykmapipo/gridfs-stream which at least hast this issue solved. For some I also switched to mongoose-gridfs .

lobermann avatar Mar 30 '21 14:03 lobermann