J.K*_*.Ko 2 javascript firebase google-cloud-firestore
我想在上传数据之前检查文件是否确实存在于路径中。如果没有,它将为该路径设置一个新文档。如果是,它只会更新数据。
在文档中找不到执行此操作的方法。什么是最好的方法来做到这一点?这是我认为看起来相似的内容。有什么建议?谢谢!
const ref=firebase.firestore().collection('posts').doc('post_id');
if (!ref.exists) {
firebase.firestore().collection('posts').doc('post_id').set(data);
}
else {
ref.update(data);
}
Run Code Online (Sandbox Code Playgroud)
如果文档不存在,“它将设置一个新文档到路径”,如果它存在“它只会更新数据”。
您必须执行以下操作:
const ref = firebase.firestore().collection('posts').doc('post_id');
ref.set(
{foo: 'bar', bar: 'foo'},
{merge: true}
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2554 次 |
| 最近记录: |