Question
controller : app.get(/update, (req, res) => { console.log(req.query); users.replaceUser(req.query._id, req.query.name, req.query.age, req.query.email, req.query.phoneNumber) .then(updateCount => { console.log(updateCount); res.send({ updateCount: updateCount }); }) .catch(error => {
controller :
app.get(\"/update\", (req, res) => {
console.log(req.query);
users.replaceUser(req.query._id, req.query.name, req.query.age, req.query.email, req.query.phoneNumber)
.then(updateCount => {
console.log(updateCount);
res.send({ updateCount: updateCount });
})
.catch(error => {
console.error(error);
res.send({ error: 'Request failed' });
});
});
model:
const replaceUser = async (_id, req) => {
const result = await User.findOneAndUpdate({ _id: req.query._id}, req.query);
return result.nModified;
I am unfamiliar with JavaScript and cannot get this to work: I keep getting this error TypeError: Cannot read property 'query' of undefined
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started