Search code examples
androidfirebasegoogle-cloud-firestorefirebase-console

Order internal data sent to Firestore


Hi i am working with firebase. When sending a record I get messy data.

enter image description here

Is there a method to order them to my liking? Since I would like to have it in the order of the form.

I leave a fragment of my code, thank you very much for reading.

firebaseAuth.createUserWithEmailAndPassword(correo, password).addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                USERUID = firebaseAuth.getCurrentUser().getUid();
                DocumentReference documentReference = firebaseFirestore.collection("Clientes").document(USERUID);

                Map<String, Object> user = new HashMap<>();
                user.put("Nombre y Apellido", nombre);
                user.put("Correo", correo);
                user.put("Domicilio", domicilio);
                user.put("Localidad", localidad);
                user.put("Fecha" , FieldValue.serverTimestamp());
                documentReference.set(user).addOnSuccessListener(aVoid -> Log.d(TAG, "Cuenta creada, UID de usuario : " + USERUID))
                        .addOnFailureListener(e -> Log.d(TAG, "Creación de cuenta fallida: " + e.toString()));
                startActivity(new Intent(getApplicationContext(), VerificacionDeDatos.class));
                finish();
            } else {
                Light.make(snackbar, "Error al registrarse: " + task.getException().getLocalizedMessage(), R.drawable.ic_error_outline_black_24dp, android.R.color.transparent, R.color.error, Snackbar.LENGTH_SHORT).show();
            }
        });

Solution

  • Firestore document fields don't have a determined order. What you see in the screenshot is just how the Firebase console chooses to order them. You'll notice they're in alphabetical order. There's no way to change this, but you can do whatever you want with the order in your own app.