无限文档验证器模式-MongoDB

发布于 2025-01-31 06:47:11 字数 1117 浏览 2 评论 0原文

我是MongoDB的新手,我正在尝试为文件夹树创建文档验证器。本文档的目的是表示用户存储中不同文件夹和文档的位置。

我遇到的问题是,我不知道如何描述每个文件夹内部可能具有多个文件夹的事实。

到目前为止,我提出的是:

{
  bsonType: "object",
  required: ["rootTree"],
  properties: {
    rootTree: {
      bsonType: 'object',
      properties: {
        files: {
          bsonType: [
            'array'
          ],
          items: {
            bsonType: 'object',
            required: [
              'file_id',
              'name'
            ],
            properties: {
              file_id: {
                bsonType: 'objectId',
                description: 'the id of the file stored in the File collection'
              },
              name: {
                bsonType: 'string',
                description: 'the name of the file'
              }
            }
          }
        },
        folders: {
          bsonType: [
            'array'
          ]
        }
      }
    }
  }
}

因此,在本文档验证器中,我说在存储的根部可以存储不同的文件和文件夹。我要说的是,在每个文件夹中,我也可以存储许多文件和文件夹,但是如果我继续定义文件夹中的内容,它将永远持续下去。

您对如何继续定义这种行为有任何想法吗? (在不为文件夹创建集合的情况下)吗?

(在这种情况下,我可以创建类似文件夹类型的内容吗

I am new to MongoDB and I'm trying to create a document validator for a folder tree. The goal of this document is to represent where the different folders and documents are located in a user's storage.

The problem I have is that I don't know how to describe the fact that each folder may have multiple folders inside them.

What I've came up so far with is this:

{
  bsonType: "object",
  required: ["rootTree"],
  properties: {
    rootTree: {
      bsonType: 'object',
      properties: {
        files: {
          bsonType: [
            'array'
          ],
          items: {
            bsonType: 'object',
            required: [
              'file_id',
              'name'
            ],
            properties: {
              file_id: {
                bsonType: 'objectId',
                description: 'the id of the file stored in the File collection'
              },
              name: {
                bsonType: 'string',
                description: 'the name of the file'
              }
            }
          }
        },
        folders: {
          bsonType: [
            'array'
          ]
        }
      }
    }
  }
}

So in this document validator I say that at the root of the storage I can store different files, and folders. And I'd to say that in each folder I can store many files and folders as well, but if I continue to define what is inside a folder, it will continue forever.

Do you have any idea on how I could proceed to define this behavior? (without creating a collection for the folders preferably)

For instance, can I create something like a folder type in this case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

a√萤火虫的光℡ 2025-02-07 06:47:11

我决定使用另一种解决方案来描述使用“路径”字段指示文件/文件夹的位置的文件树组织。

因此,这个问题不再与我有关。

I decided to use another solution to describe a file tree organisation which is using a "path" field indication the location of the file/folder.

So this question is not relevant for me anymore.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文