Loading

Quipoin Menu

Learn • Practice • Grow

mongodb / E-commerce Cart with Mongoose
mcq
Direction: Choose the correct option

Q1.

In an e-commerce cart, how might you model a user's cart in MongoDB?
A. Both approaches are possible
B. An array of product IDs embedded in the user document
C. A separate 'carts' collection with items embedded
D. Use a relational database
Direction: Choose the correct option

Q2.

If using a separate 'carts' collection, what might each cart document contain?
A. All of the above
B. `orders` array
C. `products` field with prices
D. `userId`, an array of `items` with product details and quantity
Direction: Choose the correct option

Q3.

How would you add an item to a user's cart?
A. Find the cart document and use `$push` to add the item
B. Create a new cart document for each item
C. Update the user document
D. Use `$addToSet`
Direction: Choose the correct option

Q4.

How can you calculate the total price of items in a cart?
A. Iterate through items and sum `price * quantity` in application code
B. Both are possible
C. Store the total in a separate field
D. Use MongoDB aggregation with `$unwind` and `$sum`
Direction: Choose the correct option

Q5.

When a user checks out, what might you do with the cart data?
A. Mark the cart as checked out
B. Delete the cart document
C. All of the above are possible
D. Move the cart items to an 'orders' collection with a snapshot