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?