Materialized path tree structure with support for duplicate path IDs in MongoDB?

In the tutorial for materialized path tree structures in mongodb files, they show a simple example of how to structure data to support a simple query:

db.categories.insert( { _id: "Books", path: null } )
db.categories.insert( { _id: "Programming", path: ",Books," } )
db.categories.insert( { _id: "Databases", path: ",Books,Programming," } )
db.categories.insert( { _id: "Languages", path: ",Books,Programming," } )
db.categories.insert( { _id: "MongoDB", path: ",Books,Programming,Databases," } )
db.categories.insert( { _id: "dbm", path: ",Books,Programming,Databases," } )

      

This works great as long as it _id

is unique to each item. In our case, we are designing a course structure that should support SEO: accessible URLs like /course-a/lesson-1/introduction

. The data construct must support duplicates (for example, several courses might have a lesson called "introduction"):

  • Course A
    • Introduction (lesson)
      • Part 1 (lesson)
      • Part 2 (lesson)
    • Background (lesson)
    • ... (lesson)
  • Course B
    • Introduction (lesson)
    • Why it works (lesson)
    • ... (lesson)

Our current solution is to create tutorials created using materialized path design. This is when we realized that it would not work with duplicate lesson IDs. But before I throw it all away, I would like to ask for advice.

Is there a way to design this to support our problem using materialized paths?

+3


source to share





All Articles