I'm building a basic DMS as a feature. My current database is Mongo and I've quoted a simple doc structure that I'm currently using for nested folders.
{
"_id": "AS111",
"Name": "Test1",
"Parent": ""
},
{
"_id": "AS222",
"Name": "Test2",
"Parent": "AS111"
},
{
"_id": "AS333",
"Name": "Test3",
"Parent": "AS222"
}
Here, Test1
folder is present in the root directory, Test2
folder is nested within Test1
and Test3
folder is nested within Test2
. When performing a global search for all files and folder named Test3
, I'm able to retrieve the related information and the immediate parent folder. But how can I get the whole directory? Example: Test1 > Test2 > Test3
. My solution currently includes fetching all the Folders in from the database and searching for _id
of Test3. This is very unoptimized and does not scale well. I also thought of using aggregations in mongo but that is also a costly operation and this query will be executed every time every single user searches for a file or folder. Is there a python way of getting the path of the folder or aggregation in mongo query is the way to go?