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.
The $inc operator increments a field by a specified value and has the following form: { $inc: { <field1>: <amount1>, <field2>: <amount2>, ... } } To specify a <field> in an embedded document or in an array, use dot notation.
Starting from MongoDB 4.2 you can perform Updates with an Aggregation Pipeline. An aggregation pipeline enables more expressive updates including calculated fields and references to other field values in the same document.
You can extract the value of a field by appending that field's name to your query when using findOne() .
db.campaigns.update(
{ '_id' : ObjectId("57aea88f2f1321710f7373f8") },
{ $inc: { _a: 1000 } });
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