Query de update do MongoDB

From Basef
Jump to: navigation, search

A seguinte query:

Query query = new Query();
query.addCriteria(Criteria.where("transactionId").is(transactionId.toString()));
 
Update update = new Update();
update.set("amount.value", amount.getValue().doubleValue());
update.set("amount.currency", amount.getCurrency());
 
MongoTemplate mongo = this.getMongoTemplate();
mongo.updateMulti(query, update, Payment.class);

Equivale a:

db.payment.update(
    {
        transactionId: 15
    },
    {
        $set: {
            "amount.value": 200,
            "amount.currency": "BRL"
        }
    }
    {
        multi:true
    }
);