我有一个基于以下MongoDB架构的集合,这涉及电子商务交易,我有目的地使用单个文档来实现任何更新的原子性,如下所示。
我将在报告中提供以下三个用例。
用例1& 2对我来说很简单,但对于用例#3,我可以对模式做更多的事情,以使其更容易实现。
{
"_id":"id",
"cuid":"CUIDFromCustomerCollection",
"customerTransactions":{
{
"retailer":"www.walmart.com","purchaseAmount":"123.00","cashbackAmount":"12.00","state":"pending","transactionTimestamp":"timestampValue","updateTimestamp":"timestampValue"
},
{
"retailer":"www.walmart.com","purchaseAmount":"123.00","cashbackAmount":"12.00","state":"confirmed","transactionTimestamp":"timestampValue","updateTimestamp":"timestampValue"
} ,
{
"retailer":"www.walmart.com","purchaseAmount":"123.00","cashbackAmount":"12.00","state":"available","transactionTimestamp":"timestampValue","updateTimestamp":"timestampValue"
} ,
{
"retailer":"www.walmart.com","purchaseAmount":"123.00","cashbackAmount":"12.00","state":"redeemed","transactionTimestamp":"timestampValue","updateTimestamp":"timestampValue"
}
}
答案 0 :(得分:0)
该设计适用于所有三种用例。
对“customerTransactions.state”进行索引将有助于优化。