aheckmann / gridfs-stream

Easily stream files to and from MongoDB
MIT License
615 stars 120 forks source link

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

Open HolgerFrank opened 6 years ago

HolgerFrank commented 6 years ago

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

lobermann commented 6 years ago

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)
Schinkentanz commented 6 years ago

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')}`);
wendellpereira commented 6 years ago

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. =)

Wisedemic commented 6 years ago

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);

lykmapipo commented 6 years ago

133 will help

xelaz commented 4 years ago

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

cmouli96 commented 4 years ago

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

traoremp commented 3 years ago

Has this been resolved ?

lobermann commented 3 years ago

@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 .