{"action":"created","issue":{"url":"https://api.github.com/repos/dancannon/gorethink/issues/192","labels_url":"https://api.github.com/repos/dancannon/gorethink/issues/192/labels{/name}","comments_url":"https://api.github.com/repos/dancannon/gorethink/issues/192/comments","events_url":"https://api.github.com/repos/dancannon/gorethink/issues/192/events","html_url":"https://github.com/dancannon/gorethink/issues/192","id":81883690,"number":192,"title":"Missing some IDs on insert.","user":{"login":"omeid","id":1453118,"avatar_url":"https://avatars.githubusercontent.com/u/1453118?v=3","gravatar_id":"","url":"https://api.github.com/users/omeid","html_url":"https://github.com/omeid","followers_url":"https://api.github.com/users/omeid/followers","following_url":"https://api.github.com/users/omeid/following{/other_user}","gists_url":"https://api.github.com/users/omeid/gists{/gist_id}","starred_url":"https://api.github.com/users/omeid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omeid/subscriptions","organizations_url":"https://api.github.com/users/omeid/orgs","repos_url":"https://api.github.com/users/omeid/repos","events_url":"https://api.github.com/users/omeid/events{/privacy}","received_events_url":"https://api.github.com/users/omeid/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-28T11:15:52Z","updated_at":"2015-05-29T12:06:11Z","closed_at":null,"body":"Running the following code:\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"log\"\r\n\r\n\trt \"github.com/dancannon/gorethink\"\r\n)\r\n\r\ntype T struct {\r\n\tId string\r\n\tA  bool\r\n\tB  int\r\n}\r\n\r\nfunc main() {\r\n\r\n\tdb, err := rt.Connect(rt.ConnectOpts{\r\n\t\tAddress: rethinkServerAddr,\r\n\t})\r\n\tif err != nil {\r\n\t\tlog.Fatal(err)\r\n\t}\r\n\tdefer db.Close()\r\n\r\n\tdb.SetMaxOpenConns(20)\r\n\tdb.SetMaxIdleConns(20)\r\n\r\n \r\n\tgo func() {\r\n\t\tstream, err := rt.Db(\"test\").Table(\"ts\").Changes().Field(\"new_val\").Run(db)\r\n\t\tif err != nil {\r\n\t\t\tlog.Println(err)\r\n\t\t\treturn\r\n\t\t}\r\n\t\tv := T{}\r\n\t\tfor stream.Next(&v) {\r\n\t\t\t//To avoid race condition/overwrite by next call.\r\n\t\t\tfunc(x T) {\r\n\t\t\t\tfmt.Printf(\"%#v\\n\", x)\r\n\t\t\t}(v)\r\n\t\t}\r\n\t\terr = stream.Err()\r\n\t\tif err != nil {\r\n\t\t\tlog.Println(err)\r\n\t\t}\r\n\t\tlog.Println(\"END OF stream.\")\r\n\t}()\r\n\r\n\tfor i := 0; i < 30; i++ {\r\n\t\terr := rt.Db(\"test\").Table(\"ts\").Insert(T{A: i%2 == 0, B: i}).Exec(db)\r\n\t\tif err != nil {\r\n\t\t\tlog.Fatal(err)\r\n\t\t}\r\n\t}\r\n\r\n}\r\n```\r\nWill give you, some Ids missing:\r\n\r\n```\r\nmain.T{Id:\"ff5c1e65-9ab1-49b8-befc-b5efca5af414\", A:false, B:1}\r\nmain.T{Id:\"6ca2c8de-9b6e-43d5-910b-fcf849890652\", A:true, B:2}\r\nmain.T{Id:\"9ebb807d-2604-4017-8ad3-70c50a75cac2\", A:false, B:3}\r\nmain.T{Id:\"ce006af3-aba3-4997-8837-5e839b1d9f9d\", A:true, B:4}\r\nmain.T{Id:\"802178f4-29bb-4eea-a54a-75a14ebdee00\", A:false, B:5}\r\nmain.T{Id:\"2ebddde6-5d49-4730-be96-232c64292a79\", A:true, B:6}\r\nmain.T{Id:\"9b7b14da-4030-4cd6-baea-6926c3639faf\", A:false, B:7}\r\nmain.T{Id:\"a0717c2d-dd35-444b-b0f2-7fd8a9aac279\", A:true, B:8}\r\nmain.T{Id:\"d69d5f68-f78d-46ea-853f-59239005fbf3\", A:false, B:9}\r\nmain.T{Id:\"946de5c6-c107-44a6-8e21-f85e54ace4b8\", A:true, B:10}\r\nmain.T{Id:\"bef36a90-e96c-4584-a983-82b626d127a8\", A:false, B:11}\r\nmain.T{Id:\"\", A:true, B:12}\r\nmain.T{Id:\"ad108124-908b-4b2a-92bd-186a8f1878ad\", A:false, B:13}\r\nmain.T{Id:\"4f665222-6edf-4eec-a870-4d2eedd84703\", A:true, B:14}\r\nmain.T{Id:\"\", A:false, B:15}\r\nmain.T{Id:\"d0bf350d-d3f1-4fb7-bc58-2f4ceec927cd\", A:true, B:16}\r\nmain.T{Id:\"\", A:false, B:17}\r\nmain.T{Id:\"fa075833-d07c-454d-bca6-dff1524a3254\", A:true, B:18}\r\nmain.T{Id:\"\", A:false, B:19}\r\nmain.T{Id:\"b1fdda33-aea9-4dae-959c-c8719fc158d6\", A:true, B:20}\r\nmain.T{Id:\"8431c425-424f-4247-a668-6ea15ec88f99\", A:false, B:21}\r\nmain.T{Id:\"\", A:true, B:22}\r\nmain.T{Id:\"d088c93c-879c-4ccd-a10d-d09b4daaa9f4\", A:false, B:23}\r\nmain.T{Id:\"\", A:true, B:24}\r\nmain.T{Id:\"9696a198-7ce9-4dc0-a1f4-02d10ce38412\", A:false, B:25}\r\nmain.T{Id:\"627a2974-1590-4f59-8182-6a81beec84e2\", A:true, B:26}\r\nmain.T{Id:\"a086c9c6-c146-405d-bcf3-2af03b042b6d\", A:false, B:27}\r\nmain.T{Id:\"90f3e7d3-38b0-43cc-b778-9d889023cf5c\", A:true, B:28}\r\nmain.T{Id:\"47c21238-8eb5-419c-9cfb-b2d1df61b02d\", A:false, B:29}\r\n```\r\n\r\nWhile running `r.db('test').table('ts').changes()(\"new_val\")` in Data Explorer shows a correct id per document."},"comment":{"url":"https://api.github.com/repos/dancannon/gorethink/issues/comments/106783873","html_url":"https://github.com/dancannon/gorethink/issues/192#issuecomment-106783873","issue_url":"https://api.github.com/repos/dancannon/gorethink/issues/192","id":106783873,"user":{"login":"dancannon","id":414768,"avatar_url":"https://avatars.githubusercontent.com/u/414768?v=3","gravatar_id":"","url":"https://api.github.com/users/dancannon","html_url":"https://github.com/dancannon","followers_url":"https://api.github.com/users/dancannon/followers","following_url":"https://api.github.com/users/dancannon/following{/other_user}","gists_url":"https://api.github.com/users/dancannon/gists{/gist_id}","starred_url":"https://api.github.com/users/dancannon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dancannon/subscriptions","organizations_url":"https://api.github.com/users/dancannon/orgs","repos_url":"https://api.github.com/users/dancannon/repos","events_url":"https://api.github.com/users/dancannon/events{/privacy}","received_events_url":"https://api.github.com/users/dancannon/received_events","type":"User","site_admin":false},"created_at":"2015-05-29T12:06:11Z","updated_at":"2015-05-29T12:06:11Z","body":"After running some tests I have tracked this issue down to the code that decodes the database result. Basically the raw result from the database looks something like this:\r\n\r\n```go\r\nmap[string]interface {}{\"A\":false, \"B\":41, \"Id\":\"\", \"id\":\"f0d4bc93-048a-4383-8c99-15ef0218a067\"}\r\n```\r\n\r\nBecause there are two \"Id\" fields I think that because of how Go randomly iterates through maps the driver randomly uses either \"Id\" or \"id\" when decoding into the `T` struct. I will look into making this more reliable (if possible) but until then you can fix this issue by adding a struct tag, for example:\r\n\r\n```go\r\ntype T struct {\r\n\tId string `gorethink:\"id\"`\r\n\tA  bool\r\n\tB  int\r\n}\r\n```"}}