2016-06-08 42 views
1

我們正試圖在Web應用程序中表示此數據。將以何種方式表示此數據?我們考慮使用關係結構,但數據本質上是分層的。在這種情況下使用MongoDB更好嗎? health data什麼是更好的方式來表示這個多維數據?

+0

層次結構是一種關係。關係數據庫可以有效地處理您的數據,IMO更有利於數據完整性和查詢的簡易性。 – reaanb

+0

Hello @reaanb,你有鏈接到我可以看到的一些示例模式嗎? –

+0

看看http://stackoverflow.com/questions/4048151/what-are-the-options-for-storing-hierarchical-data-in-a-relational-database。我的首選方法是當遞歸查詢不可用或有效時,使用閉合表補充的簡單鄰接表模型(即父鍵和子鍵列)。 – reaanb

回答

0

根據評論mongo動態模式是一個完美的解決方案。

讓我們假設我們有我們的文檔結構是這樣的:

report { 
    _id... 
    documentBycode { 
     _id : "G8", 
     dataSource, 
     remarks, 
     fields : [{ 
       indicator : "sucide", 
       baseline { 
        data, 
        year, 
        source 
       }, 
       milestone[{ 
         year : 2017, 
         value : 15 
        }, {} 

       ] 

       ... 
       ... 
       fields : [{ 
         name : "nfhs1996", 
         value : "n/a", 
         order : 1 /* this is not mandatory*/ 
        }, { 
         name : "ndhs2011", 
         value : "n/a", 
         order : 2 
        } 
       ] 
       ] 
      } 
     } 

那麼你可以添加/根據需要修改[數組]中的元素,一定可以得到通過檢索數據存儲只有一個文檔報告數據。

什麼也可能是有趣的,你可以有存儲在同一個集合多張不同勢報告結構 - 這樣你就可以從字面上存儲完整的視圖模型數據AS IS

任何評論歡迎!

+0

那麼查詢數據有多簡單呢?我沒有MongoDB工作經驗? –

+0

@ShresthaRohit quering與sql類似 - 你需要知道文檔的id或特定的字段值 – profesor79

相關問題