I have my route below that takes the form data and tries to input the page and archive into an existing name that is already in the mongodb. My form data is being sent correctly as I can see from my console.log.
Now I need to insert the page name and archive name where it equals name. Whether it already has data or not. They are already setup with array in the schema. You can see my schema below
Any ideas on how to get this setup?
router.post('/add-page', function(req, res, next){
if(req.body.name && req.body.page && req.body.archive){
//create object with form input
var pageData = {
client: req.body.name,
page: req.body.page,
archive: req.body.archive
};
console.log(pageData);
//insert data
Page.then(function(db){
delete req.body._id;
db.collection('pages').insertOne();
});
return res.render('index', { title: 'Home' });
}else{
var err = new Error('All fields required.');
err.status = 400;
return next(err);
}
});
var ClientSchema = new mongoose.Schema({
client: {
type: String,
required: true,
trim: true,
unique: true,
},
page: {
type: [],
trim: true,
},
archive: {
type: [],
trim: true,
}
});