How to query recursive MongoDB Document? [File System of files and folders]

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.

  1. user’s _id
  2. the array of folder names in order ex. [‘root’, ‘nestedFolder1’, ‘nestedFolder2’, ‘etc…’]
  3. _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[];
}