duanhuayong6687 2017-10-13 10:15
浏览 58

使用golang插入Firebase数据库时数据丢失

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 :- enter image description here

This is screenshot of Task Structure :-

enter image description here

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器