我正在开发一个小型应用程序,它将存储有关用户、帐户和交易的信息。用户将拥有许多帐户(可能少于 10 个)并且这些帐户将有许多交易(可能有 1000 个)。阅读文档似乎表明嵌入如下是要走的路...
{
"username": "joe",
"accounts": [
{
"name": "account1",
"transactions": [
{
"date": "2013-08-06",
"desc": "transaction1",
"amount": "123.45"
},
{
"date": "2013-08-07",
"desc": "transaction2",
"amount": "123.45"
},
{
"date": "2013-08-08",
"desc": "transaction3",
"amount": "123.45"
}
]
},
{
"name": "account2",
"transactions": [
{
"date": "2013-08-06",
"desc": "transaction1",
"amount": "123.45"
},
{
"date": "2013-08-07",
"desc": "transaction2",
"amount": "123.45"
},
{
"date": "2013-08-08",
"desc": "transaction3",
"amount": "123.45"
}
]
}
]
}
我的问题是......由于文档中的事务列表可能会增长到 1000 个,因此数据会变得碎片化并降低性能。我最好有一个文档来存储用户和不会增长得那么大的帐户,然后有一个单独的集合来存储引用到帐户的交易。或者,还有更好的方法?