Answer the question
In order to leave comments, you need to log in
How does findByIdAndUpdate work?
Doesn't find the record in the second case, everything works in the first one. Help me understand why.
app.post('/pari', function (req, res, next) {
Pari.findById("55058fc4e9cbc78c1b9973d2", function(err, par){
console.log(par);
});
Pari.findByIdAndUpdate("55058fc4e9cbc78c1b9973d2", {date: Date.now, active: true}, function(err, curPari){
console.log(curPari);
});
});
Answer the question
In order to leave comments, you need to log in
If I understood everything correctly, then you want to update the date and status for the document in the second case. For this you need to use "Update operators" mongodb. Your request should look something like this
Pari.findByIdAndUpdate("55058fc4e9cbc78c1b9973d2", {$set:{date: Date.now, active: true}}, function(err, curPari){
console.log(curPari);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question