在文档参考上使用set(),update(),delete()时,Firestore WriteBatch无法执行 [英] Firestore WriteBatch Fails to execute when using set(), update(), delete() on Document Reference
问题描述
我正在使用 Firestore
作为后端构建一个 Android
应用程序.我正在写文档中的多个集合,在某些情况下可以写
到文档中, update
文档,然后删除
所有文档在同一 WriteBatch
中.每当用户创建时,以后在相同的 WriteBatch
中,删除
文档都会使我的应用程序崩溃.下面是我收到的代码和错误.
I am building an Android
application using Firestore
as my backend. I am writing to multiple collections within a document, and in some instances can write
to a document, update
the document, then delete
the document all within the same WriteBatch
. Whenever a user creates, then later deletes
a document within the same WriteBatch
my application crashes. Below is the code and error I receive.
private void executeBatchedWrite() {
WriteBatch batch = db.batch();
DocumentReference doc = notebookRef.document("123");
batch.set(doc, new Note("New Note", "New Note", 1));
batch.update(doc, "timestamp", FieldValue.serverTimestamp());
batch.delete(doc);
batch.commit();
}
我的应用程序崩溃,并且出现以下错误:
My app crashes and I receive the following error:
java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
at com.google.firebase.firestore.g.zza.zzb(SourceFile:324)
at com.google.firebase.firestore.g.zzd.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
推荐答案
我已经确定这是一个错误,并将其报告给了Google.进一步的测试表明,此问题可能是特定于将FieldValue.serverTimestamp()写入文档的,最终将在同一批写入中将其删除.如果将FieldValue.serverTimestamp()替换为其他值(例如:System.currentTimeMillis()),则问题似乎消失了.
I've determined this was a bug and reported it to Google. Further testing indicates that this issue may be specific to writing FieldValue.serverTimestamp() to a document that will eventual be deleted within the same batch write. If the FieldValue.serverTimestamp() is replaced with a different value (ex: System.currentTimeMillis()), the issue seems to go away.
这篇关于在文档参考上使用set(),update(),delete()时,Firestore WriteBatch无法执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!