Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

46 lines (30 sloc) 1.562 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.

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)

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
Jump to Line
Something went wrong with that request. Please try again.