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 7962257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:17:21+00:00 2026-06-04T05:17:21+00:00

I am implementing a ruby on rails app with mongodb/mongoid and I am bit

  • 0

I am implementing a ruby on rails app with mongodb/mongoid and I am bit confused about the better indexing/searching structure.
I have a field staff in a model and a staff can be either of type – production, broker, office.
Each staff is a Person. Each type can have multiple staff.

So I have two approaches:

1). Make staff as an array and store it like

[{:key => 'broker', :name => "Broker Name", :person_id => "654978"},
{:key => 'office', :name => "Office Staff 1", :person_id => "564654"},
{:key => 'office', :name => 'another office', :person_id => '79878'}]

2). Make is a Hash and store is as
{:brokers => [{:person_id =>
2134, :name => 'Broker 1'}],
:office =>> [{:person_id =>
2131, :name => 'Office 1'}, {:person_id => 1231, :name => 'Office
2'}]}

I want to index these documents and should be able to search documents like, where office = ‘465456’.

  • 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-04T05:17:22+00:00Added an answer on June 4, 2026 at 5:17 am

    If you store it as a hash you need several indexes. Since you then have to index the office name for each of the keys in the hash. If you store it as an array you only need 1 index.

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

Sidebar

Related Questions

I am implementing in Ruby on Rails, and i have 2 views. In my
I am implementing in Ruby on Rails, and I have a view, with all
As a bit of a fun project I'm implementing a Beatnik interpreter in Ruby.
I have built a blog using Ruby on Rails. New to both. I am
I'm implementing an application in ruby on rails (although this is a minor detail)
I am implementing in Ruby on Rails, and i want to do so, that
I am implementing in Ruby on Rails and I am trying to work with
I am implementing my own RSA algorithm in ruby to learn more about the
I am implementing elasticsearch on tire in my ruby on rails application. I am
I am implementing a data structure using Ruby and the BinData gem. I need

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.