aheckmann / gridfs-stream

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

Grid.collection is not reflecting name passed in at creation time (Possible bug) #59

Closed longieirl closed 9 years ago

longieirl commented 9 years ago

Hi,

I have the following code:

var gfs;
db.once('open', function () {
    gfs = new Grid(db.db, mongoose.mongo);
    gfs.collection('assets');
});

The problem is that assets is not being reflected in the schema - I've even gone into the gridfs-steam module and hardcode the value i.e.

Grid.prototype.collection = function (name) {
  name || (name = this.mongo.GridStore.DEFAULT_ROOT_COLLECTION);
  return this._col = this.db.collection("assets.files");
}

and still the name appears as fs.files in the schema. If the collection name is set like above then it will never use this name. To enforce the name you need to do the following;

var target = commonService.getGridFs().createWriteStream({
            filename: fileItem.originalname,
            mode: 'w',
            metadata: metaData,
            root: 'assets' // only works when this is specified here
        });
joelabair commented 9 years ago

I can confirm this as well. Using options.root

Reggino commented 9 years ago

This is fixed in v1.0.1 by @healiha

Thanks for the feedback.