1

I am getting this error - Cannot read property 'ObjectId' of undefined at Stream.GridWriteStream at gfs.createWriteStream. Funny things is my implementation was working fine till yesterday. I cannot figure out what went wrong.

var Grid = require('gridfs-stream');

Grid.mongo = mongoose.mongo;
var gfs;

var mongoose = require('mongoose');
    mongoose.connect('mongodb://user:pass@example.com:15879/thing', function (error) {
        if (error) {
            console.log(error);
        }
    });

var conn = mongoose.connection;
conn.once('open', function callback(){
  gfs = Grid(conn.db);
  var writestream = gfs.createWriteStream({
    filename: "secure"
  });
});
shiv
  • 383
  • 1
  • 4
  • 17
  • Have you checked that conn.db is not `undefined`? – Alex Logan Apr 07 '16 at 15:24
  • Its not undefined- Small excerpt from the log -{ databaseName: 'kidstories', dbCache: {}, children: [], topology: – shiv Apr 07 '16 at 15:27
  • Strange. The fact that `gfs.createWriteStream` is failing suggests that either `gfs` wasn't created properly or there is a problem with the `filename`. – Alex Logan Apr 07 '16 at 15:30
  • Hey Alex, I tried this- https://github.com/aheckmann/gridfs-stream/issues/74. But still did not work. Can you please take a look. – shiv Apr 07 '16 at 16:12
  • Did you try doing `mongo.BSONPure = require('bson').BSONPure`? – Alex Logan Apr 08 '16 at 08:15

0 Answers0