0

In the firestore collection named 'doctor' there are different fields including the field 'role'. I want to add the doctors into firestore with a role named doctor. How can I do this? Following is the code that successfully adds data into the database. If you can, tell me the way to add data with a specific field name. Thanks in advance.

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);
  });
}

pghasandi
  • 19
  • 7

1 Answers1

0

Notice that Record is a javascript object, and how you create a document in Cloud firestore, is by passing an object with all the filled attributes into the add method like what you did in service.ts, and how you pass in an attribute is via Record[ATTRIBUTE_NAME] = ATTRIBUTE_VALUE

Hence I believe what you need to just to add in the line Record[‘role’] = “doctors” into component.ts

Prashin Jeevaganth
  • 1,223
  • 1
  • 18
  • 42