2017-11-17 3 views
-3
{ 
    "_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" 
                 } 
                ] 
             }, 

            ] 
        }, 
       ] 
} 

innerFolder、subinnerFolderなど(内部フォルダ構造がネストされるように)以下のjson形式のmongodbスキーマを作成する必要があります。以下のJsonのためにmongodbスキーマを作成するには?

+0

json-schemaを使用していますか? –

答えて

0

を見てみましょう。
ここでの唯一の問題は、ヌル値です。
可能性の1つは、テキストとして保存することです。 null値を格納しないことを検討してください。

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 ] 
    }] 
    }] 
} 
+0

iは、スキーマの上に使用してnodejsでこれらの詳細を追加することができますどのように –

+0

あなたがマングースの[ドキュメント]を見てすることができます(http:// mongoosejs .com/docs/index.html)。 – TGrif

0

以下はhttps://jsonschema.net/#/によって生成されたjsonスキーマです。必要に応じて編集することができます。マングースのスキーマの場合は、ここでマングーススタイルでスキーマの例がある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" 
         ] 
         } 
        } 
        } 
       } 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
} 
+0

どのように私はmongo dbでそれを行うことができますか? var mainFolder =新しいRepositorySchema({}); var subFolder = new RepositorySchema(); var subsubFolder = new RepositorySchema(); mainFolder.innerFolders.addは( subFolder.innerFolders.add(subsubFolder)サブフォルダ; –

関連する問題