Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

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

Open

Description

@jisamathew

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

Activity

  1. singhanuj620 commented on Mar 20, 2020

    @singhanuj620

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

  2. Chris-QIU commented on Jun 19, 2021

    @Chris-QIU

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions