Closed
Description
- Android Studio version: 2020.3.1. Patch 3
- Firebase Component: Firestore
- Component version: firebase-bom:29.2.0
Describe the problem
When is Android client offline and I add a new document to firestore and then I call update data on this document then snapshot contain only updated attribute.
Steps to reproduce:
- My phone is in flight mode
- I register the snapshots listener
- I create new movie document. DocumentSnapshot.getData() contain all document data (Snapshot: {name=Star wars (episode 1), likes=0}, ID: X07AxnfSg6bU2lAx5MAP)
- I update movie document. DocumentSnapshot.getData() contain only likes value (Snapshot: {likes=1}, ID: 07AxnfSg6bU2lAx5MAP). I would expect it to contain the entire document therefore Snapshot: {name=Star wars (episode 1), likes=1}, ID: 07AxnfSg6bU2lAx5MAP
Create new document
Map<String, Object> user = new HashMap<>();
user.put("name", "Star wars (episode " + (episode++) + ")");
user.put("likes", 0);
// Add a new document with a generated ID
db.collection("movies")
.add(user)
.addOnSuccessListener(documentReference -> Log.d(TAG, "Movie added with ID: " + documentReference.getId()))
.addOnFailureListener(e -> Log.w(TAG, "Error adding movie", e));
Snapshot listener
db.collection("movies")
.addSnapshotListener((snapshots, e) -> {
if (e != null) {
Log.w(TAG, "listen:error", e);
return;
}
for (DocumentSnapshot dc : snapshots.getDocuments()) {
Log.d(TAG, "Snapshot: " + dc.getData() + ", ID: " + dc.getId());
}
});
Update document
db.collection("movies")
.document(documentId)
.update("likes", lastLikes++);
Log
Create new document
2022-03-14 10:27:46.712 24467-24467/cz.datasys.firebaseissue D/Firebase: Snapshot: {name=Star wars (episode 1), likes=0}, ID: X07AxnfSg6bU2lAx5MAP
After update
2022-03-14 10:28:11.426 24467-24467/cz.datasys.firebaseissue D/Firebase: Snapshot: {likes=1}, ID: X07AxnfSg6bU2lAx5MAP