My web application is like quiz app, the user should answer a question and the server will store the user's result in mongoDB database. what I is want is after saving the document in the database I want to get this document to send it to user in the browser note saving documents works fine. code looks like this (assuming the user's result is 10):
const User_Result = require("../models/result_model")
router.post("/quiz/results", (req, res)=>{
var result = new User_Result({
_id: req.user._id,
userResult: 10
})
result.save()
//that should get data and send it but it send empty []
User_Result.find({_id: req.user._id}).then(data=>{
res.send(data)
})
})
I think the problem that it looks for the data before saving it.