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

查看:59
本文介绍了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

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() 方法="https://firebase.google.com/docs/reference/js/firebase.firestore.DocumentReference" rel ="nofollow noreferrer"> DocumentReference 都返回一个包含void的Promise,而 CollectionReference

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的回答一致):有趣的是,使用创建文档,您会返回(即通过API端点响应)

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天全站免登陆