Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
HolgerFrank opened this issue Feb 1, 2018 · 9 comments

Comments

@HolgerFrank
Copy link

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
mongodb/node-mongodb-native#1527

@lobermann
Copy link

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
Copy link

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
Copy link

wendellpereira commented Apr 11, 2018

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
Copy link

Wisedemic commented Apr 27, 2018

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
Copy link

#133 will help

aslafy-z added a commit to aestetype/mongo-oplog that referenced this issue Jun 21, 2018
Made to fix issue similar to this one: aheckmann/gridfs-stream#125
aslafy-z added a commit to aestetype/mongo-oplog that referenced this issue Jun 21, 2018
Needed to fix this issue: aheckmann/gridfs-stream#125

TLDR: breaking change in node-mongodb-native package prevent from using new mongo version
aslafy-z added a commit to aestetype/mongo-oplog that referenced this issue Jun 21, 2018
Needed to fix this issue: aheckmann/gridfs-stream#125

TLDR: breaking change in node-mongodb-native package prevent from using new mongo version
MelroyNoronha added a commit to MelroyNoronha/gridfs-stream that referenced this issue Jan 24, 2019
@xelaz
Copy link

xelaz commented Aug 17, 2020

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

@cmouli96
Copy link

cmouli96 commented Nov 8, 2020

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

@traoremp
Copy link

Has this been resolved ?

@lobermann
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants