Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (30 sloc) 1.53 KB

MongoMapper Plugins

Versioned Update

This plugin implements the “Update if Current” (see Mongo documentation) Atomic operation.

The plugin will add a _version key to your model and increment it on each save. Each save will ensure that it only saves if the database contains the record with the same version at the time of save and raises an InvalidVersion error if the versions do not match.


class Model
  include MongoMapper::Doument

Updating Modifiers

This plugin will update the internal value of a model when using modifiers like model.set, model.increment, model.decrement, model.push, model.pull and model.push_uniq


#in initializer
MongoMapper::Document.append_inclusions MongoMapper::Plugins::UpdatingModifiers::Addition

#Use your model as usual
counter => Counter.create(:count => 1)
counter.increment(:count, 1)
counter.count #=> 2

Auto increment ids

This plugin will allow the auto generation of numeric ids Uses the “Insert if Not Present” technique (see Mongo documentation)


class Model
  include MongoMapper::Document

#Assuming the first document in the collection #=> 1 #=> 2 etc