{"action":"opened","issue":{"url":"https://api.github.com/repos/BroilerBear/test-task/issues/16","repository_url":"https://api.github.com/repos/BroilerBear/test-task","labels_url":"https://api.github.com/repos/BroilerBear/test-task/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/BroilerBear/test-task/issues/16/comments","events_url":"https://api.github.com/repos/BroilerBear/test-task/issues/16/events","html_url":"https://github.com/BroilerBear/test-task/issues/16","id":382162710,"node_id":"MDU6SXNzdWUzODIxNjI3MTA=","number":16,"title":"WriteRecord has redundant mongodb calls","user":{"login":"akhripko","id":7147396,"node_id":"MDQ6VXNlcjcxNDczOTY=","avatar_url":"https://avatars2.githubusercontent.com/u/7147396?v=4","gravatar_id":"","url":"https://api.github.com/users/akhripko","html_url":"https://github.com/akhripko","followers_url":"https://api.github.com/users/akhripko/followers","following_url":"https://api.github.com/users/akhripko/following{/other_user}","gists_url":"https://api.github.com/users/akhripko/gists{/gist_id}","starred_url":"https://api.github.com/users/akhripko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akhripko/subscriptions","organizations_url":"https://api.github.com/users/akhripko/orgs","repos_url":"https://api.github.com/users/akhripko/repos","events_url":"https://api.github.com/users/akhripko/events{/privacy}","received_events_url":"https://api.github.com/users/akhripko/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-19T11:04:05Z","updated_at":"2018-11-19T11:04:05Z","closed_at":null,"author_association":"NONE","body":"instead of \r\nerr = c.Insert(&Person{Name: in.Name, Email: in.Email, Phone: in.Phone, Fphone: in.Fphone, Timestamp: time.Now()})\r\n\r\n\t// look for that specific user in the database and update it\r\n\t// or inform the user that the username/email already exists\r\n\tif mgo.IsDup(err) {\r\n\r\n\t\tlog.Println(\"Record is already exists\", err)\r\n\t\t// Update\r\n\t\tlog.Println(\"Updating record\")\r\n\t\tcolQuerier := bson.M{\"email\": in.Email}\r\n\t\tchange := bson.M{\"$set\": bson.M{\"name\": in.Name, \"email\": in.Email, \"phone\": in.Phone, \"fphone\": in.Fphone, \"timestamp\": time.Now()}}\r\n\t\terr = c.Update(colQuerier, change)\r\n\t}\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n\r\ntry use\r\nUpsert\r\nhttps://godoc.org/gopkg.in/mgo.v2#Collection.Upsert"}}
{"actor":{"display_login":"akhripko"}}