GridFS + Mongoose helper
npm i gridstorage
const Storage = require('gridstorage');
const mongo = require('mongodb');
const { MongoClient } = mongodb
MongoClient.connect(uri, (err, db) => {
if (err) {
throw new Error(err);
}
const storage = new Storage(mongo, db);
To use with Mongoose:
const Storage = require('gridstorage');
const mongoose = require('mongoose');
const storage = new Storage(mongoose);
const videoBucket = storage.bucket('videos');
if (await videoBucket.count(filename) > 0) {
return next('Video exists');
}