I have a nested item schema in an invoice schema as given below :
var InvoiceSchema = new db.Schema({
title: {
type: String,
required: true
},
description: String,
clientId: db.Schema.ObjectId,
companyId: db.Schema.ObjectId,
poNumber: Number,
invoiceNumber: {
type: Number,
default: 1000
},
taxApplied: {
type: Boolean,
default: false
},
feeApplied: {
type: Boolean,
default: false
},
lastUpdated: {
type: Date,
default: Date.now
},
createdOn: {
type: Date,
default: Date.now
},
status: {
type: String,
enum: ['presented', 'entered', 'hold', 'paid',
'partially paid', 'reversed', 'void'],
required: true
},
invoiceItems: [InvoiceItemSchema]
});
var InvoiceItemSchema = new db.Schema({
invoiceId: {
type: db.Schema.ObjectId,
required: true
},
description: String,
qty: Number,
rate: Number,
isFlatFee: {
type: Boolean,
default: false
}
});
I am able to create a new invoiceItem and push it directly into the invoice invoiceItems array, and read it when it's in there, but I am having a lot of trouble trying to update and delete. I was looking at this site here
http://tech-blog.maddyzone.com/node/add-update-delete-object-array-schema-mongoosemongodb
But I couldn't seem to get any of that to work.
I know in that blog he is using $set to update things but it looks like it only updates one field and I want to update any field based on user input and not a hard coded field. I don't have any code to show right now because I am quite lost but some help would be appreciated!