I am developing an application that uses MongoDB (typegoose) to store file system-like (recursive) documents composed of files and folders. However, I do not know how to query such a schema. For querying, I am provided the following.
- user’s _id
- the array of folder names in order ex. [‘root’, ‘nestedFolder1’, ‘nestedFolder2’, ‘etc…’]
- _id of the last folder chosen
The schema is as follows
import { Types } from "mongoose";
interface File {
_id: Types.ObjectId;
fileName: string;
isDir: false;
content: string;
title: string;
description: string;
}
interface FileSystem {
_id: Types.ObjectId;
folderName: string;
isDir: true;
files: File[] | [];
folders: FileSystem[] | [];
}
interface Project {
_id: Types.ObjectId;
projectName: string;
fileSystem: FileSystem;
}
interface User {
_id: Types.ObjectId;
projects: Project[];
}