I'm using mongoose and mongoose-gridfs module and can't figure out how to fix error. Can easily add file to my db and read it:
router.get('/:id', (req, res)=> {
if (gridfs == null) {
gridfs = require("mongoose-gridfs")({
collection: 'attachments',
model: 'Files'
});
Attachment = gridfs.model;
}
let stream = Attachment.readById(req.params["id"]);
}
But when i'm using the same way in delete route:
router.delete('/:id', (req, res)=> {
if (gridfs == null) {
gridfs = require("mongoose-gridfs")({
collection: 'attachments',
model: 'Files'
});
Attachment = gridfs.model;
}
Attachment.unlinkById(req.params["id"], (err) => {
});
}
It's throw me an error TypeError: Cannot read property 'unlink' of null. What am i doing wrong?