title: Is there any method to pass multiple selected option value to MongoDB using React JS?
body: <p>I want to pass the selected option value to my back end using React Select. First I want to select option from React Select then I want to store into the usestate from where i am sending it to the database.</p>
  <p>The code look like:</p>
  <pre><code>const options = [
      { value: 'AUD', label: 'AUD' },
      { value: 'CAD', label: 'CAD' },
      { value: 'CHF', label: 'CHF' },
  ]
  export default function MemberInformation() {
      const { t } = useTranslation();
  
      const value2 = useContext(DataContext);
      const [currency, setCurrency] = value2.currency;
      const[favcur,setFavCur]=useState([]);
       const[memberData,setMemberData]=useState([]);
      const [member,setMember]=useState({_id:&quot;&quot;,name:&quot;&quot;,prefCurrency:[]})
           var name,valueV;
          const handleInputs=e=&gt;{
            console.log(&quot;Updated &quot;,member)
            name=e.target.name;
            valueV=e.target.value;
            setMember({...member,[name]:valueV})
            if (name == &quot;prefCurrency&quot;)
            {
              setFavCur(e);
              setMember({...member,[name]:valueV})
              setCurrency(e);
            }
          }
          const postData= ()=&gt;{
            setMemberData({...memberData,...member})
            const { _id,name,prefCurrency}=member;
            var UpdatedMemInfo ={_id,name,,prefCurrency};
            axios.put('/memberInfoUpdate', UpdatedMemInfo)
            .then( res =&gt; {
              alert('Updated successfully!');
             }   
            )
            .catch(err =&gt; {
              console.log(err.response);
              alert('An error occurred! Try submitting the form again.');
            });
         } 
  useEffect(() =&gt; {
          async function fetchBooks() {
            const response = await fetch('/memberinfo');
            const json = await response.json();
            setMemberData(json.memberLogin);
            setMember(json.memberLogin);
        }
        fetchBooks();
    },[]);
  return (
  &lt;div&gt;
   &lt;Row &gt;
                    &lt;Col &gt;&lt;Form.Text className=&quot;text-muted&quot;&gt;{t('Name')}&lt;/Form.Text&gt;&lt;/Col&gt;
                    &lt;Col&gt;&lt;Form.Control size=&quot;sm&quot; type=&quot;text&quot; name=&quot;name&quot; placeholder=&quot;Enter Name&quot; value={member.name} onChange={e=&gt;handleInputs(e)}/&gt;&lt;/Col&gt;
                &lt;/Row&gt;
   &lt;Row &gt;
                    &lt;Col &gt;&lt;Form.Text className=&quot;text-muted&quot;&gt;{t('Preferred Currency')}&lt;/Form.Text&gt;&lt;/Col&gt;
                    &lt;Col&gt;
                    &lt;Select options={options} placeholder=&quot;Select Currency&quot; isMulti name=&quot;prefCurrency&quot; value={member.prefCurrency}  onChange={handleInputs} /&gt;
                     &lt;/Col&gt;
                &lt;/Row&gt;   
  &lt;/div&gt;
   )
  }
  </code></pre>
  <p>The error is that &quot;Cannot read properties of undefined name&quot; and page appears blank. When i want to select any option value it does not select anything from the options data.
  <code>preferred Currency(prefCurrency)</code> is basically an array type in mongoose schema.
  It looks like:
  <a href="https://i.stack.imgur.com/kwehL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kwehL.png" alt="enter image description here" /></a></p>
  <p>How can this issue be solved? , how can i pass multiple selected option value to the MongoDB back end?</p>