Shopping cart for online store?

Did the user through a session and then there is the issue of implementation of the basket. When you click the item "add To cart" what should happen to the product added to the cart for this user? In the database create a user model:
let mongoose = require('mongoose');

let User = new mongoose.Schema({

exports.User = mongoose.model('User',User);

You should add the property Basket in the form of an array? And when you throw the data in this property , and then take and draw in the Cart? Advise how correctly to do?
June 5th 19 at 21:01
1 answer
June 5th 19 at 21:03
let Cart = new mongoose.Schema({
 userId: { type: String, required: true, index: true, ref: 'User' },

I'd do a separate collection. And document user not to overload the data, and the track abandoned baskets, etc.
ie it will be one big basket for all users , but the documents will be id like users and we can simply sample to take those items whose id matches session id of the current user? - Maxwell43 commented on June 5th 19 at 21:06
Each user's basket - marcus.Wel commented on June 5th 19 at 21:09
and how to fill it out? here the user clicked add to cart and what will happen? Create a document of the basket with the same id as the user? and if he press again the add to cart does not create another basket with the same id? - Maxwell43 commented on June 5th 19 at 21:12
when adding a product see whether the document in the collection basket userId === user id; if there is, add to it, if not create a new one.
In the basket the items (array), in which id and add the products. - rossie.Cro commented on June 5th 19 at 21:15
understood thank you - Maxwell43 commented on June 5th 19 at 21:18

Find more questions by tags MongoDBExpress.jsSessionsHTTP CookiesJavaScript