Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

373
Vistas
Add to cart feature using Express, nodeJS and Mongoose

Im about to create the Add-to-cart feature to my project but I have some questions first. Do I need a Cart schema? Because I don't think I would store products to a cart Schema.

I started with this, creating a cart into user.

const UserSchema = new Schema({
    email: {
        type: String,
        required: true,
        unique: true
    },
    reputation: Number,
    cart: {
        items: [{
            productId: {
                type: mongoose.Types.ObjectId,
                ref: 'Product',
                required: true
            },
            qty: {
                type: Number,
                required: true
            }
        }],
        totalPrice: Number
    }
})

My User controller, of course empty.

module.exports.renderCart = (req, res) => {
    const product = req.body.product;
    // console.log(req.body.product)
    res.render('users/cart', { product })
}

It is okay to start with is? Also I want the cart session end at some point. Of course I need to create maybe a cart Class with methods like Add() remove() and so on. How can I do that and use it in the user controller?? Thank you in advance!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda