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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:25:55+00:00 2026-05-23T11:25:55+00:00

In MongoDB I’m doing a geonear query on a collection containing ~3.5 million objects

  • 0

In MongoDB I’m doing a geonear query on a collection containing ~3.5 million objects to return results near a certain lat/long. This query runs great if I have a basic 2d index on the object:

db.Listing.ensureIndex( { Coordinates: "2d" } );

However now I also want to filter by other fields (Price, Property Type, Year Built, Beds, Baths, etc…) within the geonear query. When I add to the query things like Price <= 10000000 then the query starts to slow down. I don’t have any indexes on these other fields so I’m wondering what the best approach is performance-wise.

I tried adding separate indexes for each of the other fields (11 total indexes on the collection) however this made the query time out every time, I guess because a collection can only handle having so many indexes?

db.Listing.ensureIndex( { Coordinates: "2d" } );
db.Listing.ensureIndex( { Price: 1 } );
db.Listing.ensureIndex( { Beds: 1 } );
db.Listing.ensureIndex( { Baths: 1 } );
etc...

Now I’m thinking of having just 1 compound index on the collection like so:

db.Listing.ensureIndex( { Coordinates: "2d", Price: 1, PropertyType: 1, YearBuilt: 1, Beds: 1, Baths: 1, HouseSize: 1, LotSize: 1, Stories: 1 } );

Is this the correct approach or is there a better way?

  • 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-23T11:25:56+00:00Added an answer on May 23, 2026 at 11:25 am

    Yes, compound index is probably the way to go. See http://www.mongodb.org/display/DOCS/Geospatial+Indexing#GeospatialIndexing-CompoundIndexes for details.

    The only issue I see here is that you have a lot of fields in that index which will make it rather big so you may want to only have indexes on fields with high cardinality. Use explain() to optimize this.

    Also, given your dataset it might be hard to keep the index right balanced (and thus it will start hitting disk when it runs out of physical memory) which will slow things down considerably.

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

Sidebar

Related Questions

I have a MongoDB query that's taking an unreasonably long time to run, but
I have a MongoDB Collection called Questions which holds JSON Objects that look like
MongoDB does provide a compact command to free deleted space on a single collection,
Using mongodb I'm trying to remove a property (_id) from a child collection (ListingFeatures)
I have a MongoDB collection and need to find the max() value of a
I've created a MongoDB aggregation query that will give me the sum of data
MongoDB seems like it is using an inefficient query pattern when one index is
In MongoDB I have a collection of documents called 'clients', where each document is
Simple mongodb collection which stores sent emails: { msgid: objectid senderid: <some objectid>, sendername:
Does MongoDB offer a find or query method to test if an item exists

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.