Uploading files to MongoDB is possible thanks to Mongo's GridFS filesystem. With Sails, you can accomplish this with very little additional configuration using the Skipper adapter for MongoDB's GridFS.
Install it with:
$ npm install skipper-gridfs --save
Then use it in one of your controllers:
uploadFile: function (req, res) {
req.file('avatar').upload({
adapter: require('skipper-gridfs'),
uri: 'mongodb://[username:password@]host1[:port1][/[database[.bucket]]'
}, function (err, filesUploaded) {
if (err) return res.serverError(err);
return res.ok();
});
}
If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.