Mongoid Indexing

Programmatic index creation and removal for Mongoid.

Install

gem 'mongoid_indexing'

Then bundle it!

Usage

Programmatic access to index creation and removal is useful in project where you don’t have access to rake tasks such as those for mongoid:db. This is fx the case when using Rails engines.

Scenario: Using Mongoid Geospatial to create geo positions for properties. For geo searches to work, you need to create 2d indexes!

Updated to work with:

github.com/mongoid/mongoid/blob/master/lib/rails/mongoid.rb

(Since March 2013)

# RANDOM PROPERTIES
describe Property do
  before :all do
    Mongoid::Indexing.create_indexes
  end

  after :all do
    Mongoid::Indexing.remove_indexes
  end

  before :each do
    10.times do
      Property.create type: 'apartment', position: random_point_within(10.kms)
    end      
  end
end

Enjoy ;)

Contributing to mongoid_indexing

Copyright © 2012 Kristian Mandrup. See LICENSE.txt for further details.