2014-06-09 86 views
0

我正在使用JavaScript(沒有任何框架)來創建一個僅客戶端的應用程序,將使用MongoDB來存儲數據。我可以用兩種方式來模擬我的數據。我該如何建模我的JS應用程序的數據

有人可以幫我理解哪個更合適。

  • 路#1

    [{ 
        title: "bucketList", 
        id: 1, 
        tasks: [{ 
         title: "play soccer for world league", 
         id: 1, 
         done: false, 
         comments: ["fifa 2014 is about to start", "need to go buy a Brazil T-shirt"] 
        }, { 
         title: "start a school", 
         id: 2, 
         done: true, 
         comments: ["start with being a mentor"] 
        }] 
    }, { 
        title: "to-do", 
        id: 2, 
        tasks: [{ 
         title: "create a todo App", 
         id: 1, 
         done: false, 
         comments: [] 
        }, { 
         title: "watch GOT", 
         id: 2, 
         done: false, 
         comments: ["whitewalkers seems to be in no hurry"] 
        }] 
    }] 
    
  • 路#2

    [{ 
        collection - title: "bucketList", 
        collection - id: 1, 
        title: "play soccer for world league", 
        id: 1, 
        done: false, 
        comments: ["fifa 2014 is about to start", "need to go buy a Brazil T-shirt"] 
    }, { 
        collection - title: "bucketList", 
        collection - id: 1, 
        title: "start a school", 
        id: 2, 
        done: true, 
        comments: ["start with being a mentor"] 
    }, { 
        collection - title: "to-do", 
        collection - id: 2, 
        title: "create a todo App", 
        id: 1, 
        done: false, 
        comments: [] 
    }, { 
        collection - title: "to-do", 
        collection - id: 2, 
        title: "watch GOT", 
        id: 2, 
        done: false, 
        comments: ["whitewalkers seems to be in no hurry"] 
    
    }] 
    

回答

0

我的兩個便士都:

我實際上取決於你想如何處理你的數據。

方式#1你可以一次管理一個完整的辦公室清單,許多辦公室方式#2讓你可以直接訪問每個辦公室。

方式#1可以很容易地從一個列表中訪問所有待辦事項,但例如更新「完成」將會更加方便,因爲它是一個數組。

方式#2使得「完成」的更新更容易,但是您需要一些迭代/聚合來找到所有待辦事項列表。

方式#2似乎更容易處理我,因爲例如更新更容易處理,而多個文檔的查找很容易處理。 還要考慮您想要對數據執行哪些操作,例如,如果您有到期日期,並且想要在所有待辦事項列表中顯示所有應有任務,則方式2將爲def。更好的選擇。

相關問題