【问题标题】:How to filter field value and send data into the firestore collection?如何过滤字段值并将数据发送到 Firestore 集合?
【发布时间】:2020-06-20 15:42:16
【问题描述】:

在名为“医生”的 Firestore 集合中,有不同的字段,包括字段“角色”。我想将医生添加到具有名为医生的角色的 Firestore 中。我怎样才能做到这一点?以下是成功将数据添加到数据库中的代码。如果可以,请告诉我添加具有特定字段名称的数据的方法。提前致谢。

service.ts

create_Newdoctor(Record){
  return this.firestore.collection('doctors').add(Record);
}

组件.ts


CreateRecord(docForm: NgForm){
  let Record = {};
  Record['fullName']=this.fullName;
  Record['email']=this.email;

  this.DoctorService.create_Newdoctor(Record).then(res=> {
    this.fullName="";
    this.email="";
    console.log(res);
        this.message = "Added";
  }).catch(error=>{
    console.log(error);
  });
}

【问题讨论】:

    标签: firebase google-cloud-firestore angular9


    【解决方案1】:

    请注意,Record 是一个 javascript 对象,您在 Cloud Firestore 中创建文档的方式是通过将具有所有填充属性的对象传递到 add 方法中,就像您在 service.ts 中所做的那样,以及如何你传入的属性是通过Record[ATTRIBUTE_NAME] = ATTRIBUTE_VALUE

    因此,我相信您只需将Record[‘role’] = “doctors” 行添加到component.ts 中即可

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-01
      • 2019-07-03
      • 1970-01-01
      • 2023-03-24
      • 2015-08-21
      • 2020-01-07
      相关资源
      最近更新 更多