I'm facing an issue while trying to merge arrays from a request with existing arrays in a MongoDB database. Despite my attempts, the arrays do not seem to be merging as expected. Can anyone help me identify what might be causing this problem?
router.post('/add-publication-data', async (req, res) => {
try {
const publication = await Publications.findOne({ _id: req.body._id });
publication.toObject();
publication.additionalauthors.concat(req.body.additionalauthors)
publication.students.concat(req.body.students)
console.log(publication.students)
publication.institutions.concat(req.body.institutions)
publication.keywords.concat(req.body.keywords)
publication.highlights.concat(req.body.highlights)
publication.save()
.then(
data => {
res.json(data);
})
.catch(e => {
res.json({
message: e
});
});
} catch (err) { console.log(err); res.json({ message: err }) };
});