Is it possible to use materialized path trees with python?

Hi @Moritz_Honscheidt
In terms of:

It would look like the code extract below. I’ve excluded error handling, any connection details beyond assuming a default local mongod.

   from pymongo import MongoClient
   client = MongoClient()
   db = client.test
   categories_col = db.categories
   categories_col.insert_one({"subjects":[{ "_id": "Programming", "path": ",Books," }, { "_id": "Databases", "path": ",Books,Programming," }]})
   query = { "subjects.path": { "$regex": '^,Books,' } }
   print(categories_col.find(query).next())

This code segment should be sufficient to give an indicative step on where to go next. In terms of follow-ups, I’d suggest you post further questions to Working with Data or to ODM & Drivers as this has moved outside of the scope of M220P and there will be a wider pool of viewers in those forums who can provide further assistance should you require it.

Kindest regards,
Eoin

1 Like