Firestore:在添加/更新文档后取回文档,无需额外的网络调用 [英] Firestore: get document back after adding it / updating it without additional network calls

查看:24
本文介绍了Firestore:在添加/更新文档后取回文档,无需额外的网络调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在添加/更新文档后恢复文档,而无需使用 Firestore 进行额外的网络调用,类似于 MongoDB?

Is it possible to get document back after adding it / updating it without additional network calls with Firestore, similar to MongoDB?

我觉得先打电话添加/更新文档然后再打电话来获取它是愚蠢的.

I find it stupid to first make a call to add / update a document and then make an additional call to get it.

推荐答案

正如您可能在 Node.js(和 Javascript)SDK 的文档中看到的那样,这是不可能的,使用 DocumentReference 也不使用 CollectionReference.

As you have probably seen in the documentation of the Node.js (and Javascript) SDKs, this is not possible, neither with the methods of a DocumentReference nor with the one of a CollectionReference.

更准确地说,set()update()DocumentReference 的代码> 方法都返回一个Promise 包含 void,而 CollectionReferenceadd() 方法返回一个包含 DocumentReference 的 Promise.

More precisely, the set() and update() methods of a DocumentReference both return a Promise containing void, while the CollectionReference's add() method returns a Promise containing a DocumentReference.

旁注(与下面 darrinm 的回答一致):有趣的是,使用 Firestore REST API,当您创建文档,您将返回(即通过 API 端点响应)一个 Document 对象.

Side Note (in line with answer from darrinm below): It is interesting to note that with the Firestore REST API, when you create a document, you get back (i.e. through the API endpoint response) a Document object.

这篇关于Firestore:在添加/更新文档后取回文档,无需额外的网络调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆