Dhanashree patil
Dhanashree patil

Reputation: 13

How to update value in firestore

How to update the status as true:

Firestore screenshot

FirebaseFirestore rootRef = FirebaseFirestore.getInstance(); 
CollectionReference applicationsRef = rootRef.collection("Root"); 
DocumentReference applicationIdRef = applicationsRef.document("Registration"); 
applicationIdRef.update("Status",true).addOnCompleteListener(task -> { 

}).addOnFailureListener(new OnFailureListener() { 
  @Override public void onFailure(@NonNull Exception e) { 
    Log.d("TAG", "onFailure: "+e); 
  } 
});

I was doing by this approach, but I was not getting how to go till status field .

Upvotes: 1

Views: 144

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598708

The Map field is (quite deeply) nested. To update nested fields, you use dot notation like this:

applicationIdRef.update("Map1.Map2.Map3.Status",true)

Also see the Firebase documentation on updating nested fields

But even then, since the value is in an array, there's no way update a single item in an array by its index. So Map1.Map2.Map3.0.Status won't work. You will need to:

  1. Read the document from the database in your application code.
  2. Update the item in the array in the nested field.
  3. Write the entire array back to the database.

This updating a single item in an array has been covered extensively before, so I recommend checking out some of those answers too.

Upvotes: 1

Related Questions