title: Mongoose Schema Error: "Cast to string failed for value"
body: <p>hi guys i have an error when i try to send array of string with Mongoose Schema
  its work ok for the tags and not for the selectedFile..</p>
  <p>Mongoose Schema:</p>
  <pre><code>import mongoose from &quot;mongoose&quot;;
  
  const postSchema = mongoose.Schema({
    title: String,
    message: String,
    name: String,
    creator: String,
    tags: [String],
    selectedFile: [String],
    likes: {
      type: [String],
      default: [],
    },
    comments: { type: [String], default: [] },
    createdAt: {
      type: Date,
      default: new Date(),
    },
  });
  
  const PostMessage = mongoose.model(&quot;PostMessage&quot;, postSchema);
  
  export default PostMessage;
  
  </code></pre>
  <p>controller.js</p>
  <pre><code>export const createPost = async (req, res) =&gt; {
    const post = req.body;
    console.log(post);
    const newPostMessage = new PostMessage({
      ...post,
      creator: req.userId,
      createdAt: new Date().toISOString(),
    });
    try {
      await newPostMessage.save();
  
      res.status(201).json(newPostMessage);
    } catch (error) {
      res.status(409).json({ message: error.message });
    }
  };
  </code></pre>
  <p>Form.js</p>
  <pre><code>const onChange = async (event) =&gt; {
      dispatch({ type: START_LOADING });
      let imgArr = &quot;&quot;;
      let obj = event.target.files;
      for (let i = 0; i &lt; obj.length; i++) {
        try {
          const file = obj[0];
          const image = await resizeFile(file);
          imgArr.push(image);
        } catch (err) {
          console.log(err);
        }
      }
      setPostData({ ...postData, selectedFile: [&quot;imgArr&quot;] });
      dispatch({ type: END_LOADING });
    };
  </code></pre>
  <p>for the test i put dammy value of [&quot;imgArr&quot;]
  and i got this error
  message: &quot;PostMessage validation failed: selectedFile: Cast to string failed for value &quot;[ 'imgArr' ]&quot; (type Array) at path &quot;selectedFile&quot;&quot;</p>
  <p>what i can do ?
  remember for the tags its work he accept array of string</p>