aheckmann / gridfs-stream

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

TypeError: Cannot read property 'readPreference' of null at new GridStore #144

Open jisamathew opened 5 years ago

jisamathew commented 5 years ago

I have used below code for retreiving image from gridfs but getting error "Cannot read property 'readPreference' of null at new GridStore"

                var readstream = gfs.createReadStream({
                    filename: file.filename
                });

                //error handling, e.g. file does not exist
                readstream.on('error', function (err) {
                    console.log('An error occurred!', err);
                    throw err;
                });

                readstream.pipe(response);
singhanuj620 commented 4 years ago

Hey, have you got any solution. Please let me know asap. Email : singhanuj620@gmail.com

Chris-QIU commented 3 years ago

Refer to #131, you may go back and try to configure the connection of GridFs. Instead of using the connection object, you may use connection.db

const Grid = require("gridfs-stream")
let gfs

// ...connect the database

const {connection,mongo} = mongoose
gfs = Grid(connection.db, mongo)
gfs.collection('bucketName')