Creating a hierarchy of associated values

I’m fairly new to MongoDB, so not sure if this easily fits into a data modeling pattern.

We have a collection of contracts (essentially construction work to be performed), and for each contract, we need to, in our application, creating a cascading list of values.

For example:

  1. In the first drop down I select a specific region.
  2. The region I selected in the first drop down should filter the second drop down to a specific list of grids for that region.
  3. Then, based on a combination of the region and grid selected in the 2 preceding drop downs, the third drop should be filtered to a specific list of circuits.

I’m trying to figure out the best way to model the relationship between the potential values in each drop down, for each contract. Is there a modeling pattern, or other design pattern that others have used, that has worked well for this? To note, the possible list of values in the 3rd drop down, could be in the thousands - this is why we have the first and second drop down, to filter to that specific list.

I couldn’t find a topic that seemed similar to this, but if this question has been posed before, happy to research the responses given there.

thank you,

Hi, @Amy_Malecha-Kedrowski,
That doesn’t appear to be a significant issue for a database. Perhaps you could consider using an index on the region and grid field. This would allow for efficient filtering of the desired circuits.

1 Like

Thank you for your response! That makes sense, the thing I’m not sure of, is how to model the relationships in the database; so in the schema, somehow indicating that a particular circuit resides within a specific grid & region. There would be multiple circuits that reside in the same grid and region. I’m not sure if I create a document for every circuit, or there is a way to put multiple circuits in the same document, or if all of this can be embedded somehow into the contract collection.

For your task, I think both approaches will work well in MongoDB. You can add multiple circuits in one document by using an array field. Just make sure the document doesn’t go over the 16MB limit set by MongoDB.

Perfect, thank you for your help.