How would I model the following data?


Is it possible to model this tree of data, so that is searching but within a single document?


I thought about, just creating an array, and putting fiction, science fiction, general, miliatry in each element, but then I lose the hierarchical nature of the data.

Then I considered and array, but with the following structure (forgetting to include quotes of course): -

[{ level1: Fiction, Level2: Science Fiction, Level3: General},
 { level1: Fiction, Level2: Science Fiction, Level3: Action & Adventure},
 { level1: Fiction, Level2: Science Fiction, Level3: Military}]

Indexing on Subjects, level1, level2, level3, level4 etc?

Or should it be in a separate document, though it seems it should be in the main book document Or maybe both versions?

Thank you.

There is a guide about tree structures on Mongo’s website.

I think for your use case I would use Materialized Paths as it seems suitable and easy to implement. Using an array as you intend is a lot harder to query.


Thank you.

Another valuable link to add to ever expanding bookmarks :slight_smile:

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.