1

With the last improvement in matrices, you can add, update and delete an element but only in matrix.

But for:

Map<String, Object> comentarios = new HashMap<>();

I probe it and it transforms me a Map to array does not matiene the same type. Someone know how I should do it?

My code is:

final Map<String, Object> nuevoComentario = new HashMap<>();
nuevoComentario.put("comentario", FieldValue.arrayUnion("id5", "Msj add"));
db.collection("Hospedaje").document(documentGetID)
                        .update(nuevoComentario);
RKRK
  • 1,284
  • 5
  • 14
  • 18
  • Hey Christian. I'm having a really hard time following along with what you're trying to do. Can you add a `println` to the code that shows what the code delivers, and then show the values you'd expect (in the same format)? – Frank van Puffelen May 17 '19 at 01:12
  • My question is that how to manage comments HashMap? (add, update, remove), I have already been able to add, but I have not been able to modify and delete. – Christian M. Salvatierra May 17 '19 at 02:43
  • @Frank I want to do the same as this but using HashMap and not an Array : https://stackoverflow.com/questions/51202300/how-to-add-update-remove-array-elements-in-firebase-firestore-android-using-hash – Christian M. Salvatierra May 17 '19 at 02:47

1 Answers1

0

From what I understand FieldValue.arrayUnion and FieldValue.arrayRemove are just for array fields, which HashMap isn't really. Try using db.collection("Hospedaje").document(documentGetID).update("myHashMapField", "key" to /value/);

Jakub Kostka
  • 551
  • 2
  • 7
  • 20