- I am trying to insert data into my mongodb database. I am using mern stack.
- This is my user model for the city data that is in array containing
city_name
& city_code
city: [{
city_name: {type: String},
city_code: {type: String},
}],
- I am passing the values to the register function in this manner
city: [{city_name: this.state.c_name, city_code: this.state.c_code}],
- This is the function defined to register into the database
city: [{ city_name: req.body.c_name, city_code: req.body.c_code}],
- No error's message is being returned in the console. I am using a message where if the user is registered successfully it returns
User Registered
or else the error message. But I am not getting anything in the console.
- Constructor defined in the front end side to get the values
city: [{city_name: '', city_code: ''}],
- UPDATED
- This is the function I am using to post the data
export const register = newUser => {
return axios
.post('users/sign-up', {
username: newUser.username,
email: newUser.email,
phone: newUser.phone,
dob: newUser.dob,
city: [{city_name: newUser.c_name, city_code: newUser.c_code}],
password: newUser.password
})
.then(response => {
console.log('Registered')
})
}