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

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

Open
jisamathew opened this issue Sep 26, 2019 · 2 comments

Comments

@jisamathew
Copy link

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

Hey, have you got any solution. Please let me know asap. Email : [email protected]

@Chris-QIU
Copy link

Chris-QIU commented Jun 19, 2021

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

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

3 participants