I am using MongoDB and Mongoose. I currently have a like button, and when I click it I would like to increment the 'likes' field in my document. Currently my document has the following schema:
brote {
name:
content:
created:
likes:
}
and I have tested that the ID in my query matches that of the object in my database.
I consulted How do I increment a Number value in Mongoose? and Incrementing a value with mongoose? but these solutions did not seem to make any changes to my database. Perhaps there is something blatantly obvious that I am missing?
Index.js
mongoose.connect('mongodb://localhost:27017/bromies', { useUnifiedTopology: true, useNewUrlParser: true });
mongoose.set('useFindAndModify', false);
var Brote = mongoose.model('Brote', broteFormSchema);
app.post('/likes', (req, res) => {
let query = { id: req.body._id};
Brote.findOneAndUpdate(query, {$inc: { 'likes': 1 }});
})