Ok, not sure if mongodb can do this, but what I need is for the following JSON to be inserted into my currency DB.
The part we want to update is exchangehistory, we need to keep all the history of the exchange rates for that day. and the next day e.g.
for e.g
{"from":"USD","currentexchange":[{"to":"NZD","rate":"1.3194","updated":"6\/5\/20121:38am"},{"to":"KWD","rate":"0.2807","updated":"6\/5\/20121:38am"},{"to":"GBP","rate":"0.6495","updated":"6\/5\/20121:38am"},{"to":"AUD","rate":"1.0228","updated":"6\/5\/20121:38am"}],"exchangehistory":{"6\/5\/2012":[{"1:38am":[{"to":"NZD","rate":"1.3194","updated":"1:38am"}]},{"1:38am":[{"to":"KWD","rate":"0.2807","updated":"1:38am"}]},{"1:38am":[{"to":"GBP","rate":"0.6495","updated":"1:38am"}]},{"1:38am":[{"to":"AUD","rate":"1.0228","updated":"1:38am"}]}]}}
I would very likely not store this in an array like this. I would create a flat data structure that has:
This is a lot lighter on the database, as documents never grow. And if documents grow they have to be moved. You can also very easily query the current rate:
And accessing all historical information: