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

  • Home
  • SEARCH
  • 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 7583561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:42:34+00:00 2026-05-30T18:42:34+00:00

I have the following mongo document: { _id: ‘someid’, name: ‘John Doe’, address: {

  • 0

I have the following mongo document:

{
  _id: 'someid',
  name: 'John Doe',
  address: {
    city: 'Osaka',
    country: 'Japan'
  }
}

How do I index by city and country?

  • 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-05-30T18:42:35+00:00Added an answer on May 30, 2026 at 6:42 pm

    From the MongoDB documentation:

    Indexing on Embedded Fields

    You can create indexes on fields embedded in sub-documents, just as you can index top-level fields in documents. […] Instead, indexes on embedded fields allow you to use a “dot notation,” to introspect into sub-documents.

    […]

    db.people.ensureIndex( { "address.zipcode": 1 } )
    

    Mongoid uses the same Dot Notation:

    You can define indexes on embedded document fields as well.

    class Person
      include Mongoid::Document
      embeds_many :addresses
      index "addresses.street"
    end
    

    So you want something like this:

    class C
      include Mongoid::Document
      index 'address.city'
      index 'address.country'
      #...
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a document in Mongo that is structured in the following way: {
I have a Mongo collection called documents which has the following structure: { name:
I have the following MongoDB object stored in my Mongo database: array ( '_id'
I have a collection of the following sort of documents (taken from Mongo DB
I have following User model, embeds the Category model, class User include Mongoid::Document include
I have created an array in my mongo document, so it looks a bit
I have a Mongo document which holds an array of elements. I'd like to
I have an mongo query that looks like the following: {'schedule': {'$elemMatch': {'time': {'$gt':
Let's say I have the following items: ID Category Name 1 Fruit Banana 2
I have a set of records with the following structure: {u'_id': ObjectId('4e60fc677fdfb50fc3000000'), u'columns': [

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.