Skip to content

Instantly share code, notes, and snippets.

@brianhempel
Created February 22, 2011 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianhempel/837965 to your computer and use it in GitHub Desktop.
Save brianhempel/837965 to your computer and use it in GitHub Desktop.
Indexing in MongoMapper
def build_indexes!
ensure_index [["parent_id", Mongo::ASCENDING]]
ensure_index [["place_type", Mongo::ASCENDING], ["name", Mongo::ASCENDING]]
ensure_index [["ancestor_ids", Mongo::ASCENDING], ["place_type", Mongo::ASCENDING]]
end
def ensure_index(index_keys)
puts "Ensuring index on #{index_keys.map{|i| i[0]}.join(', ')}..."
collection.ensure_index index_keys
end
# it's inside the MM model so MM provides the collection method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment