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

112
Views
Adding metadata to uploaded file on MongoDB Express with Gridfs

I am trying to build an web app where users can upload their resume and send it to recruiters. I am trying to add applicantID as metadata to each uploaded file so it would be easier for the lookup function later. However, metadata doesn't show on the command-line console of mongodb.

I just want to add applicantID so I can do the look up function later. If anyone has a better idea on how I should implement this. I am open to new ideas.

this is the storing engine


//creating storing engines
const conn = mongoose.createConnection(URI)
let gfs;
let fileID = ''
conn.once('open',()=>{
  gfs = Grid(conn.db,mongoose.mongo)
  gfs.collection('uploads')
})
const storage = new GridFsStorage({
    url: URI,
    file: (req, file) => {
      return new Promise((resolve, reject) => {
        crypto.randomBytes(16, (err, buf) => {
          if (err) {
            return reject(err);
          }
          const filename = buf.toString('hex') + path.extname(file.originalname);
          console.log(fileID)
          const fileInfo = {
            filename: filename,
            bucketName: 'uploads',
            metaData:{
              applicantID: fileID,
              msg: 'Hi there'
            }
          };
          resolve(fileInfo);
        });
      });
    }
  });
const upload = multer({ storage });

This is the route where user post the file

//@route /submit-application/jobID POST
//This is where users submit the resume file
//Now you need to save this to the database
router.post('/submit-application/:jobID([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/:applicantID([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})',upload.single('file'), (req,res)=>{
  console.log(req.file)
  res.redirect('/')

})

This is a screenshot of a query I ran enter image description here

Thank you

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I just found the answer. If you want to add metadata to your file, it needs to be 'metadata' instead of 'metaData'

about 4 years ago · Juan Pablo Isaza 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!