If I have a json like follows, what would be the most efficient way to keep this and be able to increment it in a data store? Should I use Mongo since I will be able to hold on to the nested structure, or use Redis which will allow me to increment atomically? Also, is there a structure where I could only update the counters for a specific day and have it update the appropriate month and day counters?
{
"summary": [
{
"years": [
{
"yr": "2008",
"cnt": 1222,
"net": 333,
"months": [
{
"mn": "09",
"cnt": 642,
"net": 1544.4,
"days": [
{
"dy": "2",
"cnt": "3",
"net": "4"
}
]
},
{
"mn": "10",
"cnt": 3216,
"net": 6452.1
},
{
"mn": "11",
"cnt": 327,
"net": 572.8
}
]
}
]
}
]
}
For the best performance try Redis. It’s lightning fast. I don’t believe that Redis has a structure that allows automatic incrementing of children but because of the amazing performance you could use a little script to do so. Also the nested structure won’t be the biggest problem because as long as you know what type of structure your elements have you can recreate it:
and so on. It’s pretty easy to do this as long as you know what to call. If you want to have a collection of all available years for example then you create an array in
summary:yearsand so on for each dynamic array so you always know what elements are available and properly set.If you don’t want these “recreation” problems and redundant collections use Mongo. As long as you can be sure you can somehow manage to increment atomically (this document may help you). However I can’t say something about Mongo because I’ve never used it.