Reputation: 99
I want to sort the latest document matching the query then set paid property to true.
Payment.update({orderRef: paidRef} , {$set:{paid:true}}, {new: true}, function(err, doc){ });
Upvotes: 1
Views: 837
Reputation: 23515
Use findOneAndUpdate() because you only want to update one.
like :
findOneAndUpdate({
orderRef: paidRef,
}, {
$set: { paid : true },
}, {
new: true,
sort: { date: -1 },
});
with date
a field where the creation date is stored
Upvotes: 1