Hi guys,
I recently asked about this in another community and got some very kind answers, but the problem isn’t solved. They referred me to go in this category to get more viewers. in case you wanna have a look at the original question, the link’s in the comments.
The problem is, the docs of mongo in the section for Materialized Path Trees are not translated for Python, only JavaScript, which I’m not familar with yet. I guess maybe I just have to learn basic JS to use this feature.
I’d like to store data like in this example : [{ "_id": "Programming", "path": ",Books," }, { "_id": "Databases", "path": ",Books,Programming," }]
and with a simple query find all the nodes that are ascending from the path Books
: db.categories.find( { path: "^,Books," } )
. Note that I in this example already changed the syntax of mongo, as it is written for JS and I’m using Python. Of course, I don’t get any output. Python doesn’t know, what I want from it. It seems like, the features I’m asking for either have a different syntax or don’t even exist for Python.
The guys commenting under my original question suggested to use the $regex operator in Python, following this part of the docs: https://docs.mongodb.com/manual/reference/operator/query/regex/. The problem is though, that this doesn’t help with Materialized Path Trees. It only makes it possible to query data and find all the nodes, which have the asked string, like in this case Books
, but that means it also for example would find nodes with the path
Bookstore
. I mean there’s a clean feature to solve this using JS, so I guess I’m just learning this now. Though I would be more than happy if there would be a way to use this feature in Python.
Btw. here’s the link to the section of the docs about Materialized Path Trees (which I need translated for Python, if possible). https://docs.mongodb.com/manual/tutorial/model-tree-structures-with-materialized-paths/ I have already asked this in the customer support, but they referred me to the community as they don’t cover this depht of topics apparently.
Cheers!