Lance Pollard
Lance Pollard

Reputation: 79440

MongoMapper, increment and update other attributes at the same time?

How do I do the following in one operation:

I am doing this now:

Model.find_or_create_by_this_and_that(this, that).increment("a" => 1, "b" => 1)

What's the correct way to do that?

Upvotes: 1

Views: 1026

Answers (1)

Gates VP
Gates VP

Reputation: 45297

From javascript you should be able to do something like

db.model.update({"_id" : "xyz"}, {$inc : {"a":1,"b":1} })

It looks like the MongoMapper equivalent is

Model.collection.update({"_id" => self._id}, {"$inc" => {"a" => 1,"b" => 1}})

MongoMapper also seems to support an increment feature, but I'm unfamiliar with the syntax. In either case that second command looks very similar to the javascript version (and the php version), so that's probably what you're looking for.

Upvotes: 1

Related Questions