angular - Firestore 在 Angular 2 上按 id 获取文档

标签 angular firebase google-cloud-firestore

如何在 google firestore 中通过 id 获取文档?有没有一些 get() 方法?因为我搜索过但没有找到适合我的正确答案:(

更新:this.itemscollection.doc(id).get() 对我不起作用

最佳答案

试试这段代码

this.itemscollection.doc(id).ref.get().then(function(doc) {
  if (doc.exists) {
    console.log("Document data:", doc.data());
  } else {
    console.log("No such document!");
  }
}).catch(function(error) {
  console.log("Error getting document:", error);
});

关于angular - Firestore 在 Angular 2 上按 id 获取文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47224976/

相关文章:

firebase - 在 Flutter 中关闭 AlertDialog

firebase - 通过flutter在Firestore中添加嵌套数据

node.js - Firestore for Node.js 最终会转向 Web 中使用的新模块化 v9 吗?

angular - 如何在 Angular 2 中使用 @HostBinding 和 @Input 属性?

Angular 2 可观察错误 - 'Parameter ' 观察者'隐式具有 'any' 类型。'

Angular 2 客户端错误

javascript - 保存下拉菜单中最后选择的选项

javascript - 检查数据是否等于 Firebase 上的某些内容

javascript - 为什么它在安装时写入 firebase 而不是在单击时写入 native react ?

Firebase Firestore 安全规则 : Only allow collection group query if filtering by a specific field