is this the way you would store currency exchange rates for mongoDB?
It does work for us, but some limitations I see if its going to be hard for us to do a date/time search instead what we will have to do is split the date and time and then place it in a select drop down or something.
Please give me your views.
{
"currentexchange": {
"0": {
"to": "NZD",
"rate": "1.2879",
"updated": "8: 42pm"
},
"1": {
"to": "USD",
"rate": "0.9777",
"updated": "8: 42pm"
},
"2": {
"to": "KWD",
"rate": "0.2739",
"updated": "8: 42pm"
},
"3": {
"to": "GBP",
"rate": "0.6354",
"updated": "8: 42pm"
}
},
"exchangehistory": {
"2012-06-06T09: 51: 25+10: 00": {
"0": {
"to": "NZD",
"rate": "1.2875"
},
"1": {
"to": "USD",
"rate": "0.9768"
},
"2": {
"to": "KWD",
"rate": "0.2742"
},
"3": {
"to": "GBP",
"rate": "0.6351"
}
},
"2012-06-06T10: 00: 09+10: 00": {
"0": {
"to": "NZD",
"rate": "1.288"
},
"1": {
"to": "USD",
"rate": "0.9774"
},
"2": {
"to": "KWD",
"rate": "0.2743"
},
"3": {
"to": "GBP",
"rate": "0.6354"
}
},
"2012-06-06T10: 15: 07+10: 00": {
"0": {
"to": "NZD",
"rate": "1.2878"
},
"1": {
"to": "USD",
"rate": "0.978"
},
"2": {
"to": "KWD",
"rate": "0.274"
},
"3": {
"to": "GBP",
"rate": "0.6357"
}
},
"2012-06-06T10: 30: 10+10: 00": {
"0": {
"to": "NZD",
"rate": "1.2873"
},
"1": {
"to": "USD",
"rate": "0.977"
},
"2": {
"to": "KWD",
"rate": "0.2737"
},
"3": {
"to": "GBP",
"rate": "0.6352"
}
},
"2012-06-06T10: 45: 08+10: 00": {
"0": {
"to": "NZD",
"rate": "1.2879"
},
"1": {
"to": "USD",
"rate": "0.9777"
},
"2": {
"to": "KWD",
"rate": "0.2739"
},
"3": {
"to": "GBP",
"rate": "0.6354"
}
}
},
"from": "AUD"
}
So how we plain on using this.
When a user wants to withdraw money, we need to be able to get the exchange rate that they requested the withdrawal.
We also need to be able to do LIVE conversion rate changes if a user has two types of currencies and say there default is AUD and they are paying someone in USD then we need to convert it, or if they dont have enough USD and they have AUD then we need to dip into there AUD and convert some to pay the rest of the charge.
There are a couple of issues to consider here: use of IDs & multiple collections
Use of Ids
Your data format seems off. Consider the following in a
currentExchangecollection:This will be the easiest layout to query.
Multiple Collections
You will want to break out
currentExchangeandexchangeHistoryinto two collections. You want thecurrentExchangeto remain small and it will leverage different indexes.As you designed it, your document would become very large and then fail.