For small file of any kind, images, videos, pdf, etc, you can insert BSON data in a collection. Here is the code in stackoverflow, thanks:)
var fs = require('fs'); var mongo = require('mongodb').MongoClient; var Binary = require('mongodb').Binary; var imagepath = fs.readFileSync("test.jpg"); var image = { id: "testid" }; image.bin = Binary(imagepath); mongo.connect('mongodb://localhost:27017/local', function (err, db) { if (err) console.log(err); db.collection('IMAGES') .insert(image, function (err, doc) { if (err) console.log(err); db .collection('IMAGES') .findOne({ id: 'testid' }, function (err, doc) { if (err) { console.error(err); } fs .writeFile('myimage', doc.bin.buffer, function (err) { if (err) throw err; console.log('Sucessfully saved!'); }); }); }); });