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

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