title: mongodb schema design to store cart rule
body: <p>I am working on a e-commerce site that uses mongodb to store the data. One of the modules will be a price/cart rule where a user will be given a coupon which they can place at checkout to get a discount.</p>
  
  <p>That is working fine and is standard, what I am unsure is how best to keep track of the number of times the user has used that coupon and in which collection to store this?</p>
  
  <p>This is the model I have thus far:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>this gives me a document like:</p>
  
  <pre><code>&gt; 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"
  }
  </code></pre>
  
  <p>I have a user collection, so should i store it inside the user document or is it better to have a coupon-log collection and count how many times the user has used a specific coupon and compare this with the user_qty from the rule collection?</p>
  
  <p>Any advice much appreciated.</p>