本文介绍了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.

推荐答案

您可以分两步完成:

// 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