0
我有一個基於下面的MongoDB模式的集合,這涉及到電子商務交易,我有目的地使用單個文檔來實現任何更新的原子性,如下所示。MongoDB Schema Design - enable atomicity
我將在報告中有以下三種用例。
- 做一個在所有州的所有customerTransactions的總和。
- 在每個州單獨處理/確認/可用/兌換所有客戶交易的總和。
- 按贖回狀態分組所有的customerTransactions,按日期分組。
用例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"
}
}