Just started with Firestore and use the SetOptions.merge()
in a Cloud Firestore Transaction like this nothing special I guess:
final Map<String, Object> visitorMap = new HashMap<>();
visitorMap.put(Visitor.NOTIFY_ON_CHAT_MESSAGE, true);
visitorMap.put(Visitor.TIME, FieldValue.serverTimestamp());
final DocumentReference docRefVisitor = mFirestore
.collection(VISITORS)
.document(theId)
.collection(VISITORS_USER)
.document(getCurrentUser().getUserId());
mFirestore.runTransaction(new com.google.firebase.firestore.Transaction.Function<void>() {
@Nullable
@Override
public void apply(@NonNull Transaction transaction) throws FirebaseFirestoreException {
transaction.set(docRefVisitor, visitorMap, SetOptions.merge());
}
})
The docs say:
If the document does not exist, it will be created. If the document does exist, its contents will be overwritten with the newly provided data, unless you specify that the data should be merged into the existing document
I experience that Visitor.NOTIFY_ON_CHAT_MESSAGE
boolean
is overwriting existing boolean
at Cloud Firestore database Document. I though the SetOptions.merge()
would not overwrite existing values?
Maybe I missed something about how Transaction works or this is a Beta related thing since CF is Beta