Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8179771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:04:22+00:00 2026-06-07T00:04:22+00:00

I have a Rails app running Mongoid on Heroku and I need to set

  • 0

I have a Rails app running Mongoid on Heroku and I need to set up some indexes to make the database faster. I’ve tried to read about it several places and I know Mongoid has some built-in functions for indexing, but I’m not sure on what to apply them and how often to index.

It is mostly my Design-model I want to index:

scope :full_member_and_show, where(full_member: true).and(show: true).desc(:created_at)
scope :not_full_member_and_show, where(full_member: false).and(show: true).desc(:created_at)

embeds_many :comments
belongs_to :designer

search_in :tags_array

attr_accessible :image,  :tags, :description, :title, :featured, :project_number, :show



field :width
field :height
field :description
field :title
field :tags, type: Array
field :featured, :type => Boolean, :default => false
field :project_number, :type => Integer, :default => 0
field :show, :type => Boolean, :default => true
field :full_member, :type => Boolean, :default => false
field :first_design, :type => Boolean, :default => false

What do I need to index, how exactly do I do it with Mongoid and how often should I do it?

ERROR UPDATE

If try to index the below:

index({ full_member: 1, show: 1 }, { unique: true })

It throws me this error:

Invalid index specification {:full_member=>1, :show=>1}; should be either a string, symbol, or an array of arrays.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:04:23+00:00Added an answer on June 7, 2026 at 12:04 am

    You don’t need to index periodically: once you’ve added an index, mongo keeps that index up to date as the collection changes. This is the same as an index in MySQL or Postgres (you may have been thinking of something like solr)

    What to index depends on what queries you’ll be making against your dataset. Indexes do carry some overhead when you do updates and consume disk space so you don’t want to add them when you don’t need them.

    You tell mongoid what indexes you want by index, for example

    class Person
      include Mongoid::Document
      index :city
    end
    

    There are loads of examples in the mongoid docs for the various kinds of indexes mongo supports.

    Then you run

    rake db:mongoid:create_indexes
    

    This determines what indexes you want (based in the calls to index in your model) and then ensures that they exist in the db, creating them if necessary. In development you’d run this after adding indexes to your models. In production it makes sense to run this as part of your deploy (you only need to if you’ve added indexes since the last deploy but it’s way easier to just do it systematically)

    There’s a lot of information about how mongo uses indexes in the documentation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails app running on Heroku. I am using paperclip for some
I have now my rails 3.2.1 app running on Heroku. I've tried to upload
I have a single-threaded Rails app running on thin in single-threaded mode on Heroku
I have a Ruby on Rails app running on Heroku. Is there an easy
I have a Rails app that is running on port 8080 that I need
I have a Rails app running at Heroku, where I'm trying to calculate the
I have had a rails 3.1 app running gmaps4rails 1.4.2 (and 1.4.8) for some
I have a Rails 3 app running on Heroku and I also have a
I have a rails app running a thin server on heroku. It currently uses
We have a rails app running on the Heroku Cedar stack, and we have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.