Firestore WriteBatch在Document Reference上使用set(),update(),delete()时无法执行

时间:2018-06-04 04:40:00

标签: android firebase google-cloud-firestore

我正在使用Android构建Firestore应用程序作为我的后端。我正在写文档中的多个集合,在某些情况下可以write到文档,update文档,然后delete文档都在同一个WriteBatch内。每当用户创建时,稍后deletes我的应用程序在同一WriteBatch内的文档崩溃。以下是我收到的代码和错误。

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();
}

我的应用崩溃了,我收到以下错误:

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)

1 个答案:

答案 0 :(得分:0)

我已经确定这是一个错误并向Google报告。进一步测试表明此问题可能特定于将FieldValue.serverTimestamp()写入最终将在同一批次写入中删除的文档。如果FieldValue.serverTimestamp()被替换为不同的值(例如:System.currentTimeMillis()),问题似乎就消失了。