user80042
user80042

Reputation: 803

Design a MongoDB schema for items inside few lists

I'm new to MongoDB and I want to design schema for eCommerce Website. I only ask about one example and I hope it will help me for the whole design.

Requirements:

I consider some options:

  1. Array of items id in Cart and Wishlist.
  2. Cart with embedded items and Wishlist with embedded items.

What are the pros and cons? Is there another way to design this?

Any example will be helpful, thanks!

Upvotes: 0

Views: 472

Answers (1)

suish
suish

Reputation: 3353

//item
{
    _id : Number,
    name : String,
    price : Number
}
//user
{
    _id : Number,
    name : String,
    profile : {
        location : String,
        age : Number,
        created_at : Date,
        /*something something something*/
    },
    wishlist : {
        item_id : [Number] // store item's _ids
    }
}

I don't think using Database to store the cart data is common way. usually you can use session/get/post/cookie instead

Upvotes: 1

Related Questions