Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

126
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda