0.0
No commit activity in last 3 years
No release in over 3 years
Provides a 'save_and_retry' method that will attempt to save a document and, if a duplicate key error is thrown by mongodb, will update the existing document instead of failing.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

> 2.0
 Project Readme

MongoidRetry Build Status Gem Version

Overcome duplicate key errors in MongoDB by catching the exception, finding the existing document, and updating it instead. Compatible with Mongoid 2 and 3.

Installation

Add this line to your application's Gemfile:

gem 'mongoid_retry'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mongoid_retry

Usage

class Fruit
  include Mongoid::Document
  include Mongoid::MongoidRetry

  field :name
  index :type, unique: true
end
Fruit.new(type: 'apple').save_and_retry

#save_and_retry takes a hash of options:

  • :retries Specifies the number of times to retry before failing. Defaults to 3.
  • :allow_delete If true, this will delete any conflicting documents if a duplicate key error is encountered.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request