Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
React Native how to send AsyncStorage data to MongoDB database?

I am not able to transfer user input which is stored in a AsyncStorage to my MongoDB database I have a MongoDB database which I start from the terminal. The console output is the following so there should not be any problems:

Server started on PORT 5000 MongoDB Connected cluster0-shard-00-02.mhqqx.mongodb.net

After this I open my React Native app with expo go and go to my register screen where a new user profile should be created. I store every required user input (name, email, etc.) in a AsyncStorage in JSON format like this:

const nameString = JSON.stringify(name)
const emailString = JSON.stringify(email)
AsyncStorage.setItem('nameInput', nameString);
AsyncStorage.setItem('emailInput', emailString);
setName('');
setEmail('');

When I print the values of the AsyncStorages in the console, there is no error and the data is displayed correctly. So the user inputs are stored in the AsyncStorages.

But after this I try to transfer the AsyncStorage data to my MongoDB database by triggering the following function with a button onPress call:

const submitHandler = async (e) => {

        if(password !==confirmpassword) {
            setMessage('Passwords do not match')
        } else  {
            setMessage(null)
            try {
                const config = {
                    headers: {
                        "Content-type": "application/json",
                    },
                };

                setLoading(true);

                const { data } = await axios.post(
                    "/api/users",
                    {name, email, password},
                    config
                );

                setLoading(false);
            } catch (error) {
                setError(error.response.data.message);
            }
        }

        console.log(email);
    };

When I check the database, no new information is displayed in my database. The database is functional and the route which is defined should be correct. What could be the problem?

I am also able to create a new user from Postman like this: enter image description here enter image description here

I have tried to search some answers for this problem for a while now but without success. Help would be much appreciated!

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You can do something like

await axios.post("/api/users",
{name, email, password},config)
.then(res=> console.log(res)
.catch(err => console.log("api error", err)

And see what you get in your corresponding terminal.
Note Your API endpoint(api/users) is not valid. Add the same URL from Postman which you're using.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!