Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

355
Views
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'unlink' of undefined at Grid.remove

I'm trying to delete a file by its id using gridfs but I get this error when calling the delete API.

Controller :

let gfs;

connect.once("open", () => {
  gfs = Grid(connect.db, mongoose.mongo);
  gfs.collection("uploads");
});

exports.deleteFile = (req, res) => {
  try {
    gfs.remove(
      { _id: req.params.id, root: "uploads" },
      (err, gridStore) => {
        if (err) {
          return res.status(404).send({ message: err });
        } else {
          return res.send({ message: "File deleted successfuly" });
        }
      }
    );
  } catch (error) {
    return res.status(500).send({
      message: error.message,
    });
  }
};
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

exports.deleteFileByFilename = async (req, res, next) => {
  const file = await gfs.files.findOne({ filename: req.params.filename });
  const gsfb = new mongoose.mongo.GridFSBucket(conn.db, { bucketName: 'uploads' });
  gsfb.delete(file._id, function (err, gridStore) {
    if (err) return next(err);
    res.status(200).end();
  });
};
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!