I need to update the "numberOfUpVotes" field for the idea with the title "Een centrale plek voor alle ideeen" in my database. How should I go about doing this?
My current code isn't throwing any errors, but it's also not updating the value as expected. Here's what I've attempted so far:
Board.findOneAndUpdate(
{"ideas.numberOfUpVotes": 23},
{$set: {"numberOfUpVotes": 2}}, // $set
{new: true},
function (err, doc) {
if (err) return res.send(500, {error: err});
console.log("hallo");
});
Here is a snippet of my data:
{
collectionName: "Board",
boardName: "IdeaBoard Schiphol",
ideas: [
{
_id: ida1,
userId: id1,
title: 'Een centrale plek voor alle ideeen',
text: 'A central hub where all ideas are displayed on a screen or something similar. Users can vote on these ideas using their phones',
date: new Date('2019-04-12'),
numberOfUpVotes: 23,
},
{
_id: ida2,
userId: id1,
title: 'Een uber voor kerstbomen',
text: 'Does something like this already exist?',
date: new Date('2019-04-11'),
numberOfUpVotes: 1,
}
],
QRcode: 'This is a QR code'
}