I am using golang and firebase for my project. Recently, I'm facing some issue regarding the data insertion into firebase, when I inserted data into firebase it is inserted into two nodes they are task and user nodes by using the below code
insertion code for user node
taskUniqueID := betterguid.New()
userData := reflect.ValueOf(m.UsersAndGroups.User)
for _, key := range userData.MapKeys() {
log.Println("inside task in user")
userTaskDetail := UserTasks{}
userTaskDetail.DateOfCreation = m.Settings.DateOfCreation
userTaskDetail.TaskName = m.Info.TaskName
userTaskDetail.CustomerName = m.Customer.CustomerName
userTaskDetail.EndDate = m.Info.EndDate
userTaskDetail.StartDate =m.Info.StartDate
userTaskDetail.JobName = m.Job.JobName
userTaskDetail.Status = helpers.StatusPending
userTaskDetail.CompanyId = companyId
userKey :=key.String()
err = dB.Child("/Users/"+userKey+"/Tasks/"+taskUniqueID).Set(userTaskDetail)
if err!=nil{
log.Println("Insertion error:",err)
return false
}
}
insertion code for task node
err = dB.Child("Tasks/"+taskUniqueID).Set(m)
if err!=nil{
log.Println("Insertion error:",err)
return false
}
Sometimes I use the above code to insert data into user. It is not inserted into the user node but inserted into the task node.mainly this problem occuring when I inserted data into many number of users, some user nodes are skipped. For example, I am adding data to 6 different users only 5 user node will inserted by this data and one among will be skipped, but this issue is not facing in all time only in specific time. Is any problem related to my code or any network issue? Please anyone help me to solve this issue. I am attaching two screen shot of my db structure
Here is screenshot of User Structure :-
This is screenshot of Task Structure :-