I'm not succeeding in updating my mongodb collection with the $inc operator. I've created a test collection to simplify things.
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
Ended up realizing had unrelated connection to mongo issues, the above code actually works very well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With