Error "TypeError: Cannot read property 'seconds' of null" when commit Firestore batch

Error "TypeError: Cannot read property 'seconds' of null" when commit Firestore batch

我在尝试批量删除集合时遇到以下错误:

TypeError: Cannot read property 'seconds' of null

at Function.fromProto (..\node_modules\@google-cloud\firestore\build\src\timestamp.js:91:47)

代码非常简单(用 TypeScript 编写):

var admin = require('firebase-admin');
...
var batch: FirebaseFirestore.WriteBatch = admin.firestore().batch();
return generic.application.admin.firestore().collection(name)
    .get()
    .then((docs: FirebaseFirestore.QuerySnapshot) => {
        docs.docs.forEach((doc:any) => {
            batch.delete(doc.ref);
        });
    })
    .then(() => {
        return batch.commit();
    });

集合为空时发生;

我通过添加一个计数器来解决,这样我就可以避免在集合为空时提交。

问题是在 firebase admin sdk 5.13.0 版中发现的,但在 5.13.1 版中仍然存在。可以找到更多信息 here