0

If i have a mongodb collection named Posts with document like following:

{
    _id: 11111,
    time:40
}

how can i add numeric value to the value 'time' on the fly using .update method? resulting with the following:

{
    _id: 11111,
    time:50
}

I was hoping something like:

Posts.update(this._id, {
    $set: {time:{time+10}}
});

which don't seem to work. Is this even possible? any ideas?

1 Answer 1

2

See $inc

Posts.update({
    _id: this._id
}, {
    $inc: {
        time: 10
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.