Я хотел бы увеличивать счетчик просмотров
на 1 при каждом доступе к моему документу. На данный момент мой код:
Document
.find({})
.sort('date', -1)
.limit(limit)
.exec();
Где здесь $ inc
?
Работы для меня (мангуста 5.7)
blogRouter.put("/:id", async (request, response) => {
try {
const updatedBlog = await Blog.findByIdAndUpdate(
request.params.id,
{
$inc: { likes: 1 }
},
{ new: true } //to return the new document
);
response.json(updatedBlog);
} catch (error) {
response.status(400).end();
}
});