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

125
Vistas
how to update mongodb nested element

I have a database of characters, this is character schema:

const charactersSchema = new mongoose.Schema({
  name: {
    type: String,
    minlength: 1,
    maxlength: 30,
    required: true,
  },
  createdAt: {
    type: Date,
    default: Date.now,
  },
  items: [{
    name: {
      type: String,
      minlength: 1,
      maxlength: 30,
      required: true,
    },
    quantity: {
      type: Number,
      default: 1,
      required: true,
    },
    category: {
      type: Number,
      default: 0,
      required: true
    },
  }],
});

I was able to do some of the actions (get all character, get one character and delete). I want to do a function where i increment items quantity by some number and if this item is not exist, create it. and do the oposite - decrement item quantity.

i read all the mongodb documentation about it but it's not working..

can someone help me with that?

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