15

What i am doing is -

db.getCollection('campaigns').update(
{'_id' : ObjectId("57aea88f2f1321710f7373f8")},
{ $set : {
        _a :  'this._a' + 1000
    }
}
);

I tried this also :

db.getCollection('campaigns').update(
{'_id' : ObjectId("57aea88f2f1321710f7373f8")},
{ $set : {
        _a :  this._a + 1000
    }
}
);

What i am getting is _a = nan.

Please help me in this. I am very new to MongoDb. What I need is add value in _a field with 1000.

1 Answer 1

21
db.campaigns.update(
   { '_id' : ObjectId("57aea88f2f1321710f7373f8") },
   { $inc: { _a: 1000 } });
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot Vora. I was completely unknown about increment operator!!!

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.