Reputation: 3572
I have a document ref user/userid23435534
and I want to update a single (document has several fields) field(nick) in that document.
I call this method: ref.ref.update("nick","test123")
and I can see from logging that ref.getpath()
is user/userid23435534
indeed.
However, after calling this method, and getting success from my OnSuccessListener
I still see that my field is not updated in the firestore database. What did I get wrong here?
EDIT:
public static void updateDocument(){
final DocumentReference ref = db.collection("user").document("userid23435534");
ref.update("nick", "test123" ) //logging shows that red.getPath is "user/userid23435534"
.addOnSuccessListener(aVoid -> {
//success is called when calling method that runs this code
}).addOnFailureListener(e -> {
//....
})
}
Upvotes: 0
Views: 1847
Reputation: 598708
I just ran this code in my local emulator, and it updates the document without problems:
DocumentReference ref = db.collection("56246892").document("uid");
ref.update("nick", "test123" ).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
System.out.println("Updated");
}
});
Are you sure the document already exists? That is required for update()
to work. If you're not sure whether the document exists, use set(..., SetOptions.merge())
.
Upvotes: 1