'Validation error for array using axios mongodb

My Article Schema contains tags field.

tags: {
  type: [String],
  required: [true, "A article must have a tags"],
  enum: {
    values: [
      "science",
      "technology",
      "gaming",
   ],
    message: "Article must have tags",
  },
},

My Pug Template for that specific field inside the form

 input#checkbox1(type="checkbox", name="science", value="science")
 | science 
 br
 input#checkbox2(type="checkbox", name="technology", value="technology")
 | technology
 br
 input#checkbox3(type="checkbox", name="gaming", value="gaming")
 | gaming
 

My javaScript file to handle POST request for sending data to the axios function in postArticle.js

const composeArticle = document.querySelector(".formComposePost");
if (composeArticle) {
  composeArticle.addEventListener("submit", (e) => {
    e.preventDefault();
    const form = new FormData();
    form.append("author", document.getElementById("userid").value);
    form.append("title", document.getElementById("heading").value);
    let tagArray = [];
    let science = document.getElementById("checkbox1");
    if (science.checked) {
      tagArray.push(science.value);
    }
    let technology = document.getElementById("checkbox2");
    if (technology.checked) {
      tagArray.push(technology.value);
    }
    let gaming = document.getElementById("checkbox3");
    if (gaming.checked) {
      tagArray.push(gaming.value);
    }

    form.append("tags", tagArray);
    form.append(
      "imageCover",
      document.getElementById("image").files[0]
    );

    postArticle(form);

PostArticle handler function I'm using axios to post the data to the API but I can't post the data

export const postArticle = async (data) => {
  try {
    const res = await axios({
      method: "POST",
      url: "http://127.0.0.1:3000/api/v1/articles/",
      data,
    });
    console.log(res);
    if (res.data.status === "success") {
      alert("success")
      window.setTimeout(() => {
        location.assign("/");
      }, 1000);
    }
  } catch (error) {
    console.log(error.response.data.message);
  }
};

my error message in the console after i submit the form

message: 'Article validation failed: tags.0: Article must have tags'


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source