Having some trouble updating a MongoDB with this code. It seems to be updating three times instead of just once due to having three dates in the posts.date field. Utilizing Vue, Mongo, and Express for this project, I have the following data structure:
{
"posts": [
{
"date": [
{ "date": "180320", "attend": "present" },
{ "date": "180321", "attend": "absent" },
{ "date": "180322", "attend": "present" }
],
"_id": "5ab7a6396b92178b5a9c5118",
"netid": "cjp",
"name": "Colton"
},
// More data entries here...
]
}
The issue lies within the following code snippet when trying to update a post. The update process is being triggered three times instead of once:
async updatePost (target, direction) {
let day = this.today;
for (let student in this.posts) {
if (this.posts[student].name == target && direction == 'left') {
// Code logic here...
await PostsService.updatePost({
id: this.posts[student]._id,
netid: this.posts[student].netid,
name: this.posts[student].name,
date: this.posts[student].date
});
}
if (this.posts[student].name == target && direction == 'right') {
// Code logic here...
await PostsService.updatePost({
id: this.posts[student]._id,
netid: this.posts[student].netid,
name: this.posts[student].name,
date: this.posts[student].date
});
}
}
this.$router.push({ name: 'Posts' });
}
This is causing confusion as it should only update once. Any help or insights would be greatly appreciated! Unfortunately, unable to provide a live example at the moment. Thank you!