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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:19:26+00:00 2026-05-31T00:19:26+00:00

I have a particular data manipulation requirement that I have worked out how to

  • 0

I have a particular data manipulation requirement that I have worked out how to do in SQL Server and PostgreSQL. However, I’m not too happy with the speed, so I am investigating MongoDB.

The best way to describe the query is as follows. Picture the hierarchical data of the USA: Country, State, County, City. Let’s say a particular vendor can service the whole of California. Another can perhaps service only Los Angeles. There are potentially hundreds of thousands of vendors and they all can service from some point(s) in this hierarchy down. I am not confusing this with Geo – I am using this to illustrate the need.

Using recursive queries, it is quite simple to get a list of all vendors who could service a particular user. If he were in say Pasadena, Los Angeles, California, we would walk up the hierarchy to get the applicable IDs, then query back down to find the vendors.

I know this can be optimized. Again, this is just a simple query example.

I know MongoDB is a document store. That suits other needs I have very well. The question is how well suited is it to the query type I describe? (I know it doesn’t have joins – those are simulated).

I get that this is a “how long is a piece of string” question. I just want to know if anyone has any experience with MongoDB doing this sort of thing. It could take me quite some time to go from 0 to tested, and I’m looking to save time if MongoDB is not suited to this.

EXAMPLE

A local movie store “A” can supply Blu-Rays in Springfield. A chain store “B” with state-wide distribution can supply Blu-Rays to all of IL. And a download-on-demand store “C” can supply to all of the US.

If we wanted to get all applicable movie suppliers for Springfield, IL, the answer would be [A, B, C].

In other words, there are numerous vendors attached at differing levels on the hierarchy.

  • 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-31T00:19:27+00:00Added an answer on May 31, 2026 at 12:19 am

    I realize this question was asked nearly a year ago, but since then MongoDB has an officially supported solution for this problem, and I just used their solution. Refer to their documentation here: https://docs.mongodb.com/manual/tutorial/model-tree-structures-with-materialized-paths/

    The concept relating closest to your question is named “partial path.”

    While it may feel a bit heavy to embed ancestor data; this approach is the most suitable way to solve your problem in MongoDB. The only pitfall to this, that I’ve experienced so far, is that if you’re storing all of this in a single document you can hit the, as of this time, 16MB document size limit when working with enough data (although, I can only see this happening if you’re using this structure to track user referrals [which could reach millions] rather than US cities [which is upwards of 26,000 according to the latest US Census]).


    References:

    http://www.mongodb.org/display/DOCS/Schema+Design

    http://www.census.gov/geo/www/gazetteer/places2k.html


    Modifications:

    Replaced link: http://www.mongodb.org/display/DOCS/Trees+in+MongoDB

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

Sidebar

Related Questions

I have a java.sql.ResultSet object that I need to update. However the result set
I have a particular class that stores a piece of data, which implements an
I have a UITableView instance tableView that displays data from a server. The tableView
I have a data frame where one particular column has a set of specific
I have a particular PHP page that, for various reasons, needs to save ~200
I have a particular application that needs to calculate something very specific, and while
I have a particular web application that like most others, has to account for
I have a particular method that is occasionally crashing with an ArgumentException: Destination array
I have one particular FLA that is crashing every time I try to compile
I have a bunch of input elements that have a particular substring in their

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.