本文介绍了Firestore-batch.add不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅适用于Firestore批处理的文档列表set()update()delete()是允许的操作.

The documentation for Firestore batch writes lists only set(), update() and delete() as permitted operations.

是否无法向批处理中添加add()操作?我需要使用自动生成的ID创建文档.

Is there no way to add an add() operation to the batch? I need a document to be created with an auto-generated id.

推荐答案

您可以分两个步骤进行操作:

You can do this in two steps:

// Create a ref with auto-generated ID
var newCityRef = db.collection('cities').doc();

// ...

// Add it in the batch
batch.set(newCityRef, { name: 'New York City' });

.doc()方法不会将任何内容写入网络或磁盘,它只是使用自动生成的ID进行引用,您以后可以使用.

The .doc() method does not write anything to the network or disk, it just makes a reference with an auto-generated ID you can use later.

这篇关于Firestore-batch.add不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 02:35