aheckmann / gridfs-stream

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

Not working with Mongoose 4.0.1 / Mongo JS 2.0 #72

Closed buunguyen closed 9 years ago

buunguyen commented 9 years ago

Using fineOne() of gridfs-stream with Mongoose 4.0 throws the following error.

Unhandled rejection Error: collection name must be a String
    at Error (native)
    at checkCollectionName (/app/node_modules/mongoose/node_modules/mongodb/lib/utils.js:70:11)
    at Function.Collection (/app/node_modules/mongoose/node_modules/mongodb/lib/collection.js:57:3)
    at Grid.findOne (/app/node_modules/gridfs-stream/lib/index.js:138:110)

It looks like Mongoose uses Mongo JS driver 2.0, which changes the signature of the Collection constructor where collection name is expected at the 4th position while gridfs-stream passes to the 2nd position. I wanted to submit a PR but am just not sure how to deal with the other parameters. Besides, I'm not sure if there's any other change.

kjunine commented 9 years ago

+1

Reggino commented 9 years ago

Hmmm... gridfs-stream is compatible with Mongodb 2.0.x and all unit tests seem to succeed... Can you add a test for this?

buunguyen commented 9 years ago

I created a bare bone repo here: https://github.com/buunguyen/gridfs-stream-issue. There's a single script which uses Mongoose 4.0 and gridfs-stream. Upon the call to findOne, it throws the error I reported above. (I tried with both Node 0.10 and iojs.)

Reggino commented 9 years ago

Thanks. I've added your test to the suite and fixed the issue... This is fixed in 1.1.1

buunguyen commented 9 years ago

Awesome, thank you!