{"action":"created","issue":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/4147","repository_url":"https://api.github.com/repos/rethinkdb/rethinkdb","labels_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/4147/labels{/name}","comments_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/4147/comments","events_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/4147/events","html_url":"https://github.com/rethinkdb/rethinkdb/issues/4147","id":71987750,"number":4147,"title":"getAll queries result the same document multiple times for some queries","user":{"login":"eliaslevy","id":725218,"avatar_url":"https://avatars.githubusercontent.com/u/725218?v=3","gravatar_id":"","url":"https://api.github.com/users/eliaslevy","html_url":"https://github.com/eliaslevy","followers_url":"https://api.github.com/users/eliaslevy/followers","following_url":"https://api.github.com/users/eliaslevy/following{/other_user}","gists_url":"https://api.github.com/users/eliaslevy/gists{/gist_id}","starred_url":"https://api.github.com/users/eliaslevy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eliaslevy/subscriptions","organizations_url":"https://api.github.com/users/eliaslevy/orgs","repos_url":"https://api.github.com/users/eliaslevy/repos","events_url":"https://api.github.com/users/eliaslevy/events{/privacy}","received_events_url":"https://api.github.com/users/eliaslevy/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/labels/tp:ReQL_proposal","name":"tp:ReQL_proposal","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/milestones/41","html_url":"https://github.com/rethinkdb/rethinkdb/milestones/subsequent","labels_url":"https://api.github.com/repos/rethinkdb/rethinkdb/milestones/41/labels","id":367201,"number":41,"title":"subsequent","description":"Issues in this milestone will be revisited after each major release during the planning stage for the major release after it. They will be moved to a specific release milestone if chosen for that release.","creator":{"login":"coffeemug","id":48436,"avatar_url":"https://avatars.githubusercontent.com/u/48436?v=3","gravatar_id":"","url":"https://api.github.com/users/coffeemug","html_url":"https://github.com/coffeemug","followers_url":"https://api.github.com/users/coffeemug/followers","following_url":"https://api.github.com/users/coffeemug/following{/other_user}","gists_url":"https://api.github.com/users/coffeemug/gists{/gist_id}","starred_url":"https://api.github.com/users/coffeemug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coffeemug/subscriptions","organizations_url":"https://api.github.com/users/coffeemug/orgs","repos_url":"https://api.github.com/users/coffeemug/repos","events_url":"https://api.github.com/users/coffeemug/events{/privacy}","received_events_url":"https://api.github.com/users/coffeemug/received_events","type":"User","site_admin":false},"open_issues":469,"closed_issues":4,"state":"open","created_at":"2013-06-30T07:32:52Z","updated_at":"2016-03-28T22:02:56Z","due_on":null,"closed_at":null},"comments":14,"created_at":"2015-04-29T20:54:54Z","updated_at":"2016-03-29T19:03:42Z","closed_at":null,"body":"If you have a record in which you index two fields with a method into a single multi index, and both fields have the same value, when you search for the field value, the ```getAll``` will return duplicates for the matching document.  E.g. if you have doc like ```{ \"a\": 1, \"b\": 1}```, and you create a single multi index that indexes both \"a\" and \"b\", then search for 1, you get back two copies of the doc.\r\n\r\nSimilarly, if the doc is ```{ \"a\": 1, \"b\": 2}```, ```.getAll(1, 2)``` will return the document twice.\r\n\r\nWhile there may be situations where this is desirable, I'd argue it fails the principle of least astonishment.  If only a single document matches, I expect to receive only a single document in return.\r\n"},"comment":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/comments/203053187","html_url":"https://github.com/rethinkdb/rethinkdb/issues/4147#issuecomment-203053187","issue_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/4147","id":203053187,"user":{"login":"danielmewes","id":505365,"avatar_url":"https://avatars.githubusercontent.com/u/505365?v=3","gravatar_id":"","url":"https://api.github.com/users/danielmewes","html_url":"https://github.com/danielmewes","followers_url":"https://api.github.com/users/danielmewes/followers","following_url":"https://api.github.com/users/danielmewes/following{/other_user}","gists_url":"https://api.github.com/users/danielmewes/gists{/gist_id}","starred_url":"https://api.github.com/users/danielmewes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielmewes/subscriptions","organizations_url":"https://api.github.com/users/danielmewes/orgs","repos_url":"https://api.github.com/users/danielmewes/repos","events_url":"https://api.github.com/users/danielmewes/events{/privacy}","received_events_url":"https://api.github.com/users/danielmewes/received_events","type":"User","site_admin":false},"created_at":"2016-03-29T19:03:41Z","updated_at":"2016-03-29T19:03:41Z","body":"@jazoom Thanks for the feedback. Good idea documenting the fact that duplicates in the key list result in duplicate results better. I've opened https://github.com/rethinkdb/docs/issues/1067 for this.\r\n\r\nIf you haven't figured this out already, you might want to look into `distinct` to remove duplicates in your key list: `tbl.getAll(r.args(r.expr(keyList).distinct()), {index: ...})`.\r\n\r\nAbout your second observation regarding getting two copies of the first and no copy of the second document: That definitely sounds wrong. I can't reproduce this unfortunately.\r\nHere's what I'm seeing:\r\n```js\r\nr.tableCreate('t1');\r\nr.table('t1').indexCreate(\"a\");\r\nr.table('t1').insert({a: \"a\", o: 1});\r\nr.table('t1').insert({a: \"a\", o: 2});\r\n\r\nr.table('t1').getAll(\"a\", \"a\", {index: \"a\"});\r\n// Returns:\r\n{\r\n    \"a\": \"a\" ,\r\n    \"id\": \"02e9d4f7-41fc-4501-80af-e10b3eb44760\" ,\r\n    \"o\": 1\r\n}\r\n{\r\n    \"a\": \"a\" ,\r\n    \"id\": \"717ed689-c07a-4796-bcc0-8711804bfc7a\" ,\r\n    \"o\": 2\r\n}\r\n{\r\n    \"a\": \"a\" ,\r\n    \"id\": \"02e9d4f7-41fc-4501-80af-e10b3eb44760\" ,\r\n    \"o\": 1\r\n}\r\n{\r\n    \"a\": \"a\" ,\r\n    \"id\": \"717ed689-c07a-4796-bcc0-8711804bfc7a\" ,\r\n    \"o\": 2\r\n} \r\n```\r\n\r\nDoes anything stand out to you that's different in your case?"}}