aheckmann / gridfs-stream

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

Root collection (maybe it will be useful to someone) #102

Open Aeonrush opened 8 years ago

Aeonrush commented 8 years ago

There is something very mysterious going on here

gfs.createWriteStream

Even if I put this line gfs.collection('fs.art'), I still have to write this

let writeStream = gfs.createWriteStream({filename: filename, root: 'fs.art'})

but this is reflected here and doesn't looks like a trouble

gfs.files

// I HAVE to put this line
gfs.collection('fs.art')
gfs.files.update({_id: file._id}, {$set: {'metadata.info': info}}, cb)

gfs.exist

Even if I put this line gfs.collection('fs.art'), I still have to write this

gfs.exist({"_id": req.params.id, root: 'fs.art'}, cb)

gfs.remove

Even if I put this line gfs.collection('fs.art'), I still have to write this

gfs.remove({"_id": req.params.id, root: 'fs.art'}, cb)

gfs.findOne and gfs.createReadStream

Works fine with gfs.collection('fs.art')

gfs.findOne({"_id": req.params.id}, cb)
gfs.createReadStream({"_id": req.params.id})
vickenliu commented 7 years ago

this is really helpful for me :) thanks

designeng commented 7 years ago

Thanks, @Aeonrush! It's useful. Nevertheless, default fs.chunks and fs.files are created (with zero documents inside).

ArthurJahn commented 7 years ago

It should be better to specify the collection only once, that would make the work much easier. Instead of that, I'm writing wrappers to specify the same thing for every database operation.

Thanks, very helpful.