我可以在 Cloud Firestore 中同时批处理 add() 和 set() 操作吗?

cbd*_*per 2 javascript firebase google-cloud-firestore

Firebase 文档中,我们得知:

批量写入

如果不需要读取操作集中的任何文档,则可以将多个写入操作作为包含set()、update() 或 delete() 操作的任意组合的单个批处理来执行。一批写入以原子方式完成,并且可以写入多个文档。

但就我而言,我需要确保add()操作(创建新文档)将与set()更新某些其他预先存在的文档的操作一起发生。

有没有办法做到这一点?

注意:我使用的是 JavaScript SDK。

and*_*res 8

如果你这样做

\n\n
 const batch = firestore().batch()\n const sampleRef = firestore().collection(\xe2\x80\x98sample\xe2\x80\x99)\n const id = sampleRef.doc().id\n batch.set(sampleRef.doc(id), {...})\n batch.commit()\n
Run Code Online (Sandbox Code Playgroud)\n\n

它应该执行 th\xc3\xa9 技巧,其 th\xc3\xa9 与 add 相同

\n