No commit activity in last 3 years
No release in over 3 years
Mongoid models are saved in one collection by default. However, when collections after too large , it could be extracted into a separated one and query form that, to make it query faster
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.17
~> 10.0
~> 3.0

Runtime

>= 6.2
 Project Readme

MongoidCollectionSeparatable

Support mongoid collections to be saved into and queried from separated collections with condition

Installation

Add this line to your application's Gemfile:

gem 'mongoid_collection_separated'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mongoid_collection_separated

Usage

Add the following line into the model class that you want to split:

1. spepated by simple field

    class Entry
      include Mongoid::Document
      include Mongoid::Timestamps
      include Mongoid::CollectionSeparated
      include Mongoid::Attributes::Dynamic

      separated_by :collection_suffix, :calc_collection_name
      class << self
        def calc_collection_name collection_suffix
          return if collection_suffix.nil?
          "entries_#{collection_suffix}"
        end
      end
    end

2. spepated by belongs to model id

    class Entry
      include Mongoid::Document
      include Mongoid::Timestamps
      include Mongoid::CollectionSeparated
      include Mongoid::Attributes::Dynamic
      belongs_to :form

      separated_by :form_id, :calc_collection_name, parent_class: 'Form'
      class << self
        def calc_collection_name form_id
          return if form_id.nil?
          "entries_#{form_id}"
        end
      end
    end


    class Form
      include Mongoid::Document
      has_many :entries
    end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/WeiGangqiang/mongoid_collection_separated

License

The gem is available as open source under the terms of the MIT License.