aheckmann / gridfs-stream

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

Cannot read property 'topology' of undefined #130

Open stelapo opened 6 years ago

stelapo commented 6 years ago

Hi. I'm new with node, so i could write wrong code.

I'm trying to read a file saved into collection "fs.files". My code is:

var readstream = gfs.createReadStream({ _id: file_id, readPreference: 'secondaryPreferred', w: -1 });

I obtaing this error: **node_modules/mongodb/lib/gridfs/grid_store.js:205 return executeOperation(this.db.s.topology, open, [this, options, callback], { ^

TypeError: Cannot read property 'topology' of undefined**

Could someone give me help? Thanx

alphonsoTheGreat commented 6 years ago

same here

caseychoiniere commented 6 years ago

Same but when trying to use gfs.remove({ _id: mongoose.mongo.ObjectId(req.params.id)})

mbharanidharan88 commented 5 years ago

I am facing the same issue and any solution for this?

let gfs;

const conn = mongoose.connection;    
conn.options = {};    
conn.once('open',  ()  => {    
  gfs = Grid(mongoose.connection, mongoose.mongo);  
  gfs.collection('uploads');

});

router.get('/image/:filename', getFile)

function getFile(req, res, next) 
{
   var readstream = gfs.createReadStream(req.params.filename);

   readstream.pipe(res)
}