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,070 points
572 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,840 points
14,300 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,020 points
10,226 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,070 points
1,175 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,020 points
571 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,840 points
740 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,840 points
3,451 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,947 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,473 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,020 points
1,369 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