NodeJS MongoDB Update inc

0 votes

I'm having trouble using the $inc operator to update my mongodb collection. To make things simpler, I made a test collection.

My code:

collection.update({field1: 'text'}, { $inc: { items: 5 } }, function (error, result) {
    if (error) reject(error);
    else resolve(result);
});

My collection:

/* 1 */
{
    "_id" : ObjectId("55d2d56a931d867cfeeba4cb"),
    "field1" : "text",
    "items" : 0
}

The update operation returns no errors, response is OK with 0 updated documents.

What am I doing wrong?

P.S. My mongodb library version is 2.0.39

[edit] I've also tried updateOne method since I saw update is deprecated in version 2, same result though

Jun 27 in Node-js by Vaani
• 7,020 points
10 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Node-js

0 votes
1 answer

How to check if a collection exists in Mongodb native nodejs driver?

Hello @kartik, The collectionNames method of the native driver's Db object accepts ...READ MORE

answered Nov 27, 2020 in Node-js by Niroj
• 82,740 points
9,742 views
0 votes
1 answer

How to make login with Nodejs and MongoDB?

MongoDB Login and Registration with Node js ...READ MORE

answered Jun 16 in Node-js by Neha
• 8,560 points
360 views
0 votes
0 answers

Mongodb updateMany() not working in nodejs

I have a collection called imported_products with ...READ MORE

Jun 27 in Node-js by Vaani
• 7,020 points
31 views
0 votes
1 answer

How do I update Node.js?

Hello @kartik, First update npm, npm install -g npm stable Then ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,740 points
274 views
0 votes
1 answer

How do I “include” functions from my other files in nodejs?

Hello @kartik, You require any js file,so you just ...READ MORE

answered Jul 9, 2020 in Node-js by Niroj
• 82,740 points
1,613 views
0 votes
1 answer

Error: listen EADDRINUSE while using nodejs?

Hello @kartik, EADDRINUSE means that the port number which listen() tries ...READ MORE

answered Jul 9, 2020 in Node-js by Niroj
• 82,740 points
2,295 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
999 views
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP