无限文档验证器模式-MongoDB
我是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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我决定使用另一种解决方案来描述使用“路径”字段指示文件/文件夹的位置的文件树组织。
因此,这个问题不再与我有关。
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.