Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!