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

111
Views
MongoError file with id not opened for writing

I am trying to get documents (images/pdf) stored in MongoDB, After receving few documents I get this error

MongoError file with id ### not opened for writing

So far I have tried multiple changes but none is working, following is the code for getting the documents,

  async getFilesData(res, bucketName, photo) {
    gfs.collection(bucketName);
    let filename = photo;
    gfs.files.findOne({ filename }, (err, file) => {
      // Check if file
      if (!file || file.length === 0) {
        return res.status(404).json({
          err: 'No file exists',
        });
      }

      const readstream = gfs.createReadStream(file.filename);
      res.set('Content-Type', file.contentType);
      return readstream.pipe(res);

      // Check if image
      /* if (file.contentType === 'image/jpeg' || file.contentType === 'image/png') {
        // Read output to browser
        const readstream = gfs.createReadStream(file.filename);
        res.set('Content-Type', file.contentType);
        return readstream.pipe(res);
      } else {
        res.status(404).json({
          err: 'Not an image'
        });
      } */
    });
  }```
about 4 years ago · Juan Pablo Isaza
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!