Frontend snippet
const dateObj = { Date: date }
const raw = JSON.stringify(dateObj)
console.log(raw);
const fetchData = async () => {
const response = await fetch('http://localhost:8000/foodsSend', {
method: 'PATCH',
headers: myHeaders,
body: raw
})
const datasss = await response.json()
console.log(datasss);
}
backend Snippet
router.patch('/foodsSend', auth, async (req, res) => {
console.log(req.body.Date)
try {
await req.user.populate({
path:'foods',
match:{
date:req.body.Date
}
}).execPopulate()
console.log(req.user.foods)
res.send(req.user.foods)
} catch (e) {
res.status(500).send()
}
})
when i make the same request from Postman, i get the array of data back, but it is not working for fetch in browser. I also console logged the date, In both the case(via browser or postman) the date is same 04/14/2020 and of type string. still only postman returns the data not the fetch api. please help