Tree Pattern - an use case

Hi,
I’m thinking whether the below use case example would be best applying Tree Pattern, what kind of tree pattern/s it might be.

State -> City -> Highway, each state has multiple cities, each city has multiple highways. However, my struggle with this kind of data is that highway might be part of multiple cities. The real application I ran into the hierarchy relationship between the child and parent can be changed more often than a highway to cities. Some examples of the model are like, A1 -> B1 -> C1, B1 -> C2, A2 -> B1 -> C2, A2 -> B3 -> C1. I can almost consider they are like graphs except for the A, B,C do show some kind of hierarchy and branching is more obvious than a random social network relation.

I saw some discussion in another topic. But it didn’t fully answer my concern about the reuse of the child branch or child node in the data.

Also, I was researching how to model graph-like data in MongoDB. Mostly findings suggest we shouldn’t model it in Mongo. I understand each kind of database has its strong suit. However, I’m kind of wondering what’s the solution (maybe not best) in Mongo.

Hi @Dan_Lu1,

Thats an interesting case and its very difficult to point out the exact pattern as it depends on the frequent queries and more details about the data.

We have this amazing blog written by our expert. Please review this if you haven’t already.

As much as I understood, Tree pattern looks like the first choice, but depending on the queries and use-case of having highways associated with multiple cities, maybe you can also use Extended reference pattern.
Having an array of city_ids in highway collection or highway-ids in city collection, depending on the queries.

Also, I would like to point out to our community forums if you have more questions and would like to be assisted with your use-case specifically.

Kanika

1 Like