Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

android - Why is my Cloud Firestore Transaction not merging when using SetOptions.merge()?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...