【发布时间】:2018-09-24 13:32:29
【问题描述】:
我像这样向 Firestore 添加数据:
db
.collection('foo')
.add({foo: 'bar'})
.then(docRef => {
console.log('Added Foo: ', docRef.id)
// do some stuff here with the newly created foo and it's id.
})
.catch(console.error)
创建文档后,我想使用新文档或特别是它的 ID。文档以有效 ID 存储在本地数据库中。
但是如何在文档创建后获取 ID?在数据与服务器同步之前,promise 不会被解析。
【问题讨论】:
-
我没有看到这里的问题。你想用 id 做点什么,所以在写着
// do some stuff here with the newly created foo and it's id.的部分做。 -
@DavidKnipe 只要你离线运行,这部分就永远不会执行
-
Dennis 您是否找到了解决此问题的好方法或解决方法,在需要离线且需要这些 id 来保存子数据的混合应用程序上易于/最佳实施?
-
@moplin 是的,请看下面我自己的答案
标签: javascript firebase google-cloud-firestore offline