We are trying to represent this data in a web application.What will be the appropriate way to represent this data? We thought of using relational structure but data are hierarchical in nature.Is it better to use MongoDB in this scenario ?
Asked
Active
Viewed 116 times
1

Community
- 1
- 1

shrestha rohit
- 2,920
- 2
- 13
- 20
-
A hierarchy is a relation. Relational databases can handle your data effectively, and IMO are better for data integrity and ease of querying. – reaanb Jun 08 '16 at 06:56
-
Hello @reaanb ,Do you have links to some example schema that I can look at? – shrestha rohit Jun 08 '16 at 07:05
-
Take a look at http://stackoverflow.com/questions/4048151/what-are-the-options-for-storing-hierarchical-data-in-a-relational-database. My preferred method is the simple adjacency list model (i.e. parent and child key columns) complemented with closure tables when recursive queries aren't available or efficient. – reaanb Jun 08 '16 at 07:32
-
is this all data you need to store - as it looks simple from that table, I'm thinking what other analytics's you will have to perform on that structure? – profesor79 Jun 08 '16 at 08:13
-
Hello @profesor79 , Yes. That's the only data. The problem is that columns like NFHS 1996, NDHS 2001 is variable i.e. more sources could be added later such as NDHS 2016 – shrestha rohit Jun 08 '16 at 08:19
1 Answers
0
As per comment mongo dynamic schemas is a perfect solution.
let assume that we have our document structured like this:
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
}
]
]
}
}
then you can add/modify elements as needed inside [arrays] and always get report data by retrieving only one document from datastore.
What's also could be interesting you could have mulitple diffrent reports structures stored in same collection - so you can literally store full ViewModel data AS IS
Any comment welcome!

profesor79
- 9,213
- 3
- 31
- 52
-
How easy would it be to query the data then? I don't have working experience with MongoDB? – shrestha rohit Jun 08 '16 at 08:47
-
@ShresthaRohit quering is similar like in sql - you need to know id of document or specific field value – profesor79 Jun 08 '16 at 08:51