mongomapper_plugins

A repository of plugins for MongoMapper

MIT License

Downloads
26.9K
Stars
3
Committers
1

= MongoMapper Plugins

== Versioned Update

This plugin implements the "Update if Current" (see Mongo documentation[http://www.mongodb.org/display/DOCS/Atomic+Operations#AtomicOperations-%22UpdateifCurrent%22]) 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.

====Usage

class Model include MongoMapper::Doument versioned_update end

== 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

====Usage

#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[http://www.mongodb.org/display/DOCS/Atomic+Operations#AtomicOperations-%22InsertifNotPresent%22])

====Usage

class Model include MongoMapper::Document auto_increment_id end

#Assuming the first document in the collection Model.create.id #=> 1 Model.create.id #=> 2 etc