Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda