S
S
source20032016-12-17 01:17:12
MongoDB
source2003, 2016-12-17 01:17:12

How to add value to mognodb field?

I have a collection with a document, the number 1 is stored in the document in the count field, how can I write a query that will update this value, adding to the already existing one (in this case it is 1) which I will indicate purely.
In sql, it would look something like this update table set field = filed + 999
I did not find anything better than choosing the value first, and then inserting the same value + the one I need in the callback, but it seems to me that this can be done in one query .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton L, 2016-12-17
@antonecma

db.collection('collectoonName').updateOne({_id : ObjectId('StringID'}, {$inc : { count : 999}});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question