我對使用MongoDB中存儲數據的電子商務網站合作。其中一個模塊將是價格/購物車規則,其中用戶將獲得優惠券,他們可以在結賬時將其放置以獲得折扣。MongoDB的架構設計到商店購物車規則
這是工作的罰款,是標準的,什麼我不確定是如何最好地保持的次數的跟蹤用戶使用的優惠券,並在該集合來存儲呢?
這是模型我迄今:
schema = new mongoose.Schema
name:
type: String
required: true
description: i18nString.schema
coupon:
type: String
index: true
type:
type: String
enum: ["cart", "price"]
required: true
quantity:
type: Number
default: 1
user_qty:
type: Number
default: 1
from:
type: Date
required: true
to:
type: Date
required: true
discount:
type: Number
default: 0
required: true
log: [
user:
type: ObjectId
ref: "User"
updatedAt: Date
status: String
]
status:
type: String
enum: ["draft", "active", "archived"]
default: "draft"
required: true
這給了我像一個文件:
> db.rules.find({}).pretty();
{
"__v" : 3,
"_id" : ObjectId("561e53dfa7e6f5f91c63e32d"),
"coupon" : "Y3E3TL-3FE00W-DDR7PP-RR27Y8",
"description" : {
"en-UK" : "English description"
},
"discount" : 10,
"quantity": 500,
"user_qty": 5,
"from" : ISODate("2015-10-13T23:00:00Z"),
"log" : [
{
"user" : ObjectId("55848edda14c975ac907ad6d"),
"updatedAt" : ISODate("2015-10-14T13:08:47.956Z"),
"_id" : ObjectId("561e53dfa7e6f5f91c63e32e")
},
{
"user" : ObjectId("55848edda14c975ac907ad6d"),
"updatedAt" : ISODate("2015-10-14T13:09:11.592Z"),
"_id" : ObjectId("561e53f7a7e6f5f91c63e32f")
},
{
"user" : ObjectId("55848edda14c975ac907ad6d"),
"updatedAt" : ISODate("2015-10-14T14:46:03.289Z"),
"_id" : ObjectId("561e6aab4adfac513594bbe6")
},
{
"user" : ObjectId("55848edda14c975ac907ad6d"),
"updatedAt" : ISODate("2015-10-15T09:44:55.827Z"),
"_id" : ObjectId("561f7597efe4eb424baac50f")
}
],
"name" : "Coupon name",
"status" : "draft",
"to" : ISODate("2015-10-23T23:00:00Z"),
"type" : "cart"
}
我有一個用戶收藏,所以我應該把它存儲用戶文件內或是否最好有一個優惠券日誌收集並計算用戶使用特定優惠券的次數,並將其與規則集合中的user_qty進行比較?
任何意見非常讚賞。
*「通常情況下,在MongoDB中,建議嘗試和嵌入文檔作爲儘可能多「。*這個斷言是錯誤的,特別是對於無界數組。 –
我刪除了這個斷言,以免混淆人。感謝您的評論。 –
@VladZ。感謝這一點,在某些情況下,優惠券將在用戶之間共享,所以我會參考用戶內的優惠券。 – khinester