i am trying to understand why the DataTo() method is not returning me all fields after passing the reference of struct in protobuf, but if i run almost same method Data() i am getting all
type Employee struct {
StartDate string
Id string
Name string
Avatar string
}
list, err := client.Collection(Company).Doc(user.CompanyID).Collection(Workers).Documents(ctx).GetAll()
if err != nil {
log.Println(err.Error())
}
values := make([]*pb.Employee, len(list))
for i, v := range list {
log.Println("By Data", &pb.Employee{
StartDate: fmt.Sprint(b.Data()["startDate"]),
Name: b.Data()["name"].(string),
Avatar: b.Data()["avatar"].(string),
Id: b.Data()["id"].(string),
})
u := &pb.Employee{}
b.DataTo(u)
log.Println("by dataTo", u.StartDate, u.Name, u.Avatar, u.Id)
values[i]= u
}
log.Println(values)
Output:
By Data start_date:"2022-07-08 12:37:47.132904 +0000 UTC" id:"DILBuRmxVzVpOVG4iPuUeb8A4tN2" name:"alap" avatar:"https://image.com"
by dataTo
By Data start_date:"2022-07-08 12:37:39.901286 +0000 UTC" id:"bH6wuk0ooCMKsh7RQqlGWtXhIZr1" name:"Jack" avatar:"https://image3.com"
by dataTo Jack https://image3.com
[avatar:"https://image.com" name:"Jakub" avatar:"https://image3.com"]
so as u could see above things are missing when trying to get document via DataTo(p) method. Anyone can see what i am doing wrong here ?
Regards.
its good practice for using
maybe in your case, there is type data in the
structthat didn't match with the schema in firestore. if I could guess theStartDatefield. if in the firestore schema it is atimestampfield, so you must settime.Timein your golang struct.