如何过滤字段值并将数据发送到 firestore 集合中?
How to filter field value and send data into the firestore collection?
在名为 'doctor' 的 firestore 集合中有不同的字段,包括字段 'role'。我想将医生添加到 firestore 中,角色名为医生。我怎样才能做到这一点?以下是成功将数据添加到数据库中的代码。如果可以,请告诉我添加具有特定字段名称的数据的方法。提前致谢。
service.ts
create_Newdoctor(Record){
return this.firestore.collection('doctors').add(Record);
}
component.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);
});
}
请注意,Record
是一个 javascript 对象,您在 Cloud firestore 中创建文档的方式是将具有所有填充属性的对象传递到 add
方法中,例如你在 service.ts
中做了什么,以及你如何通过 Record[ATTRIBUTE_NAME] = ATTRIBUTE_VALUE
传递属性
因此我相信您只需将 Record[‘role’] = “doctors”
行添加到 component.ts
在名为 'doctor' 的 firestore 集合中有不同的字段,包括字段 'role'。我想将医生添加到 firestore 中,角色名为医生。我怎样才能做到这一点?以下是成功将数据添加到数据库中的代码。如果可以,请告诉我添加具有特定字段名称的数据的方法。提前致谢。
service.ts
create_Newdoctor(Record){
return this.firestore.collection('doctors').add(Record);
}
component.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);
});
}
请注意,Record
是一个 javascript 对象,您在 Cloud firestore 中创建文档的方式是将具有所有填充属性的对象传递到 add
方法中,例如你在 service.ts
中做了什么,以及你如何通过 Record[ATTRIBUTE_NAME] = ATTRIBUTE_VALUE
因此我相信您只需将 Record[‘role’] = “doctors”
行添加到 component.ts