1

I am trying to update/create a new dataset and combine the previous value with the new one.

This is how it looks like in my Python script right now.

dailyDataset = {
    "pId" : pub,
    "oId" : off,
    "payout" : +addPayout,
}
db[dbName].update( { 'pId' : publisher, 'oId' : offer.id },  {"$set" : dailyDataset }, True)

What I try to achieve is, if the dataset pId and oId exists use the current value from "payout" and add the value from addPayout.

E.g. payout = 1.22 and addPayout = 1.22 result should be 2.44.

Any tip is welcome.

Thanks!

1 Answer 1

2

You can use the $inc operator:

db[dbName].update( { 'pId' : publisher, 'oId' : offer.id },  {"$inc" : {'payout':1.22}}, True)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.