After creating a GridFS and uploading an image using the code snippet below:
app.post("/upload", upload.single("photo"), function(req, res) {
res.redirect("/images");
})
I also have a separate model for users:
var userSchema = new mongoose.Schema({
username: String,
password: String,
posts: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "fs"
}
]
});
My current concern is associating the uploaded image in GridFS with the logged-in User. While I can retrieve the user id, I am unsure how to obtain the id of the uploaded image. I would appreciate a detailed explanation if possible as I am still a novice in this area. Thank you.