I have the following code in my page. Whenver I click on the "Add new field button" a new fields gets added to the page. What I need to accomplish is to insert every single new field into my mongodb database array.
function addInput(divName){
if (counter == limit) {
alert("You have reached the limit of adding " + counter + " inputs");
}
else {
var newdiv = document.createElement('div');
newdiv.className = "row-inputs";
newdiv.innerHTML = '<input type="text" name="productName" placeholder="product name" class="q-product-name">' +
'<input type="number" name="quantity" placeholder="1" class="q-quantity" value=1>' +
'<input type="text" name="pricePerUnit" placeholder="price" class="q-price">' +
'<input type="text" name="itemTotal" placeholder="price" class="q-total">';
document.getElementById(divName).appendChild(newdiv);
counter++;
}
}
The above is my schema:
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
var InventorySchema = Schema({
created_at: {type: Date, default: Date.now },
name: String,
list: [{
product_name: String,
quantity: Number,
pricePerUnit: Number,
itemTotal: Number
}],
invoiceTotal: Number,
comment: String,
dueDate: Date
})
var inventory = mongoose.model('inventory', InventorySchema);
module.exports = inventory;
How can I tell mongoose to add every fields created dynamically to my database?
Thank you so much!