{
"_id" : ObjectId("5a0e77f4b7368f14c088f542"),
"folderName" : "team 4",
"tag" : "search",
"ismainFolder" : true,
"innerFolder" : [
{
parentfolderId" : null,
"ismainFolder" : false,
"foldername" : "Onkar 11"
"subinnerFolder" : [
{
"parentfolderId" : null,
"ismainFolder" : false,
"foldername" : "Onkar 11"
"thirdSubFolder" : [
{
"parentfolderId" : null,
"ismainFolder" : false,
"foldername" : "Onkar 11"
},
{
"parentfolderId" : null,
"ismainFolder" : false,
"foldername" : "Onkar 11"
}
]
},
]
},
]
}
我需要为json格式创建mongodb模式,以便innerFolder,subinnerFolder等(内部文件夹结构嵌套)所以请帮助我吗?
答案 0 :(得分:0)
下面是https://jsonschema.net/#/生成的json架构。您可以根据需要进行编辑。对于Mongoose架构,请查看https://github.com/topliceanu/mongoose-gen
{
"definitions": {},
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/example.json",
"type": "object",
"properties": {
"folderName": {
"$id": "/properties/folderName",
"type": "string",
"title": "The Foldername Schema.",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"team 4"
]
},
"tag": {
"$id": "/properties/tag",
"type": "string",
"title": "The Tag Schema.",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"search"
]
},
"ismainFolder": {
"$id": "/properties/ismainFolder",
"type": "boolean",
"title": "The Ismainfolder Schema.",
"description": "An explanation about the purpose of this instance.",
"default": false,
"examples": [
true
]
},
"innerFolder": {
"$id": "/properties/innerFolder",
"type": "array",
"items": {
"$id": "/properties/innerFolder/items",
"type": "object",
"properties": {
"parentfolderId": {
"$id": "/properties/innerFolder/items/properties/parentfolderId",
"type": "null",
"title": "The Parentfolderid Schema.",
"description": "An explanation about the purpose of this instance.",
"default": null,
"examples": [
null
]
},
"ismainFolder": {
"$id": "/properties/innerFolder/items/properties/ismainFolder",
"type": "boolean",
"title": "The Ismainfolder Schema.",
"description": "An explanation about the purpose of this instance.",
"default": false,
"examples": [
false
]
},
"foldername": {
"$id": "/properties/innerFolder/items/properties/foldername",
"type": "string",
"title": "The Foldername Schema.",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"Onkar 11"
]
},
"subinnerFolder": {
"$id": "/properties/innerFolder/items/properties/subinnerFolder",
"type": "array",
"items": {
"$id": "/properties/innerFolder/items/properties/subinnerFolder/items",
"type": "object",
"properties": {
"parentfolderId": {
"$id": "/properties/innerFolder/items/properties/subinnerFolder/items/properties/parentfolderId",
"type": "null",
"title": "The Parentfolderid Schema.",
"description": "An explanation about the purpose of this instance.",
"default": null,
"examples": [
null
]
},
"ismainFolder": {
"$id": "/properties/innerFolder/items/properties/subinnerFolder/items/properties/ismainFolder",
"type": "boolean",
"title": "The Ismainfolder Schema.",
"description": "An explanation about the purpose of this instance.",
"default": false,
"examples": [
false
]
},
"foldername": {
"$id": "/properties/innerFolder/items/properties/subinnerFolder/items/properties/foldername",
"type": "string",
"title": "The Foldername Schema.",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"Onkar 11"
]
},
"thirdSubFolder": {
"$id": "/properties/innerFolder/items/properties/subinnerFolder/items/properties/thirdSubFolder",
"type": "array",
"items": {
"$id": "/properties/innerFolder/items/properties/subinnerFolder/items/properties/thirdSubFolder/items",
"type": "object",
"properties": {
"parentfolderId": {
"$id": "/properties/innerFolder/items/properties/subinnerFolder/items/properties/thirdSubFolder/items/properties/parentfolderId",
"type": "null",
"title": "The Parentfolderid Schema.",
"description": "An explanation about the purpose of this instance.",
"default": null,
"examples": [
null
]
},
"ismainFolder": {
"$id": "/properties/innerFolder/items/properties/subinnerFolder/items/properties/thirdSubFolder/items/properties/ismainFolder",
"type": "boolean",
"title": "The Ismainfolder Schema.",
"description": "An explanation about the purpose of this instance.",
"default": false,
"examples": [
false
]
},
"foldername": {
"$id": "/properties/innerFolder/items/properties/subinnerFolder/items/properties/thirdSubFolder/items/properties/foldername",
"type": "string",
"title": "The Foldername Schema.",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"Onkar 11"
]
}
}
}
}
}
}
}
}
}
}
}
}
答案 1 :(得分:0)
以下是 Mongoose 样式中的架构示例 这里唯一的困难是空值 您的一种可能性是将其存储为文本, 但要考虑根本不存储空值。
const detailFolder = {
parentfolderId: { type: String, default: null },
ismainFolder: Boolean,
foldername: String
}
const schema = {
folderName: String,
tag: String,
ismainFolder: Boolean,
innerFolder: [{
detailFolder,
subinnerFolder: [{
detailFolder,
thirdSubFolder: [ detailFolder ]
}]
}]
}