使用SetOptions.merge()时,为什么我的Cloud Firestore交易未合并? [英] Why is my Cloud Firestore Transaction not merging when using SetOptions.merge()?
问题描述
刚开始使用Firestore并使用 SetOptions.merge()
在这样的Cloud Firestore交易中,我想没什么特别的:
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());
}
})
文档说:
如果文档不存在,将创建该文档.如果文件 确实存在,其内容将被新提供的内容覆盖 数据,除非您指定应将数据合并到 现有文件
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
我发现Visitor.NOTIFY_ON_CHAT_MESSAGE
boolean
正在覆盖Cloud Firestore数据库文档中的现有boolean
.我虽然SetOptions.merge()
不会覆盖现有值吗?
也许我错过了有关交易的工作方式的一些知识,或者这与Beta相关CF是Beta版本的事情
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