DEV Community

Discussion on: Uploading Files to MongoDB with GridFS and Multer Using NodeJS

Collapse
 
staszeksoup profile image
staszeksoup

Yes, thanks but I mean when the user uploads the image, how can they add other fields? The image will need a unique filename, but can there be a title and description?

Thread Thread
 
shubhambattoo profile image
Shubham Battoo

Yes sure why not, but then that needs to be in other collection and you can reference the image objectid in the collection where you are storing the meta information for the images

Thread Thread
 
staszeksoup profile image
staszeksoup

Yes I see, so you have to save the file location and file name and add that as a string to the other collection. Thanks for your help

Thread Thread
 
shubhambattoo profile image
Shubham Battoo

File is being saved in its own collection as per gridfs, you can get an objectid for the image uploaded you can reference this objectid