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, 2022 in Node-js by Vaani
• 7,060 points
488 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,880 points
13,914 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, 2022 in Node-js by Neha
• 9,060 points
9,954 views
0 votes
0 answers

Mongodb updateMany() not working in nodejs

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

Jun 27, 2022 in Node-js by Vaani
• 7,060 points
984 views
0 votes
0 answers

How can I update NodeJS and NPM to their latest versions?

I just installed Node.js & NPM (Node Package Manager) I ...READ MORE

Aug 11, 2022 in Node-js by Neha
• 9,060 points
423 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,880 points
620 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,880 points
3,169 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
1,787 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,311 views
0 votes
1 answer

How to host MEAN stack application with Angular and nodejs on windows IIS

It's fine that you're using Angular. Be ...READ MORE

answered May 27, 2022 in Node-js by Neha
• 9,060 points
1,146 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP