{"action":"created","issue":{"url":"https://api.github.com/repos/techfort/LokiJS/issues/296","labels_url":"https://api.github.com/repos/techfort/LokiJS/issues/296/labels{/name}","comments_url":"https://api.github.com/repos/techfort/LokiJS/issues/296/comments","events_url":"https://api.github.com/repos/techfort/LokiJS/issues/296/events","html_url":"https://github.com/techfort/LokiJS/issues/296","id":122612089,"number":296,"title":"Wrong results when using indices","user":{"login":"aetna-softwares","id":8860618,"avatar_url":"https://avatars.githubusercontent.com/u/8860618?v=3","gravatar_id":"","url":"https://api.github.com/users/aetna-softwares","html_url":"https://github.com/aetna-softwares","followers_url":"https://api.github.com/users/aetna-softwares/followers","following_url":"https://api.github.com/users/aetna-softwares/following{/other_user}","gists_url":"https://api.github.com/users/aetna-softwares/gists{/gist_id}","starred_url":"https://api.github.com/users/aetna-softwares/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aetna-softwares/subscriptions","organizations_url":"https://api.github.com/users/aetna-softwares/orgs","repos_url":"https://api.github.com/users/aetna-softwares/repos","events_url":"https://api.github.com/users/aetna-softwares/events{/privacy}","received_events_url":"https://api.github.com/users/aetna-softwares/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-12-16T21:55:36Z","updated_at":"2015-12-17T11:37:28Z","closed_at":null,"body":"I have a case of figure in which adding an index on a collection leads to wrong result on search.\r\n\r\nI reproduce the problem on the sandbox : \r\n![image](https://cloud.githubusercontent.com/assets/8860618/11854992/b71eb4fc-a447-11e5-9194-539bd76c985d.png)\r\n\r\n![image](https://cloud.githubusercontent.com/assets/8860618/11854995/bedd5400-a447-11e5-952b-9ef725403ae3.png)\r\n\r\nI suspect that it maybe related to the fact that the column not always have the same variable type (sometime string, sometime boolean) but I did not find mention in documentation that index should be on column with coherent type value\r\n\r\nHere is the code used in sandbox to reproduce : \r\n```\r\n// This database has already been created for you.\r\n// var db = new loki('sandbox');\r\n\r\n// Add a collection to the database\r\nvar coll = db.addCollection(\"ir.attachment\", {\r\n    unique: ['id'],\r\n    indices: ['res_model', 'res_id', \"write_date\"]\r\n});\r\n\r\nvar jsonBLOB = '[{\"name\":\"OOR_ABC_AD01_1512_00001.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"bd4978e05ab3b34dd844688485616b1f\",\"AetnaSize\":49864,\"res_id\":143,\"id\":144},{\"name\":\"OOR_ABC_AD01_1512_00001.docx\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"abffb38135a9d82a8aec7c6c2c782aba\",\"AetnaSize\":49189,\"res_id\":95,\"id\":143},{\"name\":\"LMA_ABC_AD01_1512_00020.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"003460ce7634d7c38cdb2bb7063e4b6a\",\"AetnaSize\":562066,\"res_id\":141,\"id\":142},{\"name\":\"LMA_ABC_AD01_1512_00020.pptx\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"be71757a7771ebc68faffb999547ada2\",\"AetnaSize\":599773,\"res_id\":94,\"id\":141},{\"name\":\"LMA_ABC_AD01_1512_00019.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"033702e04d0b93ac19e5894819f6ccc9\",\"AetnaSize\":562066,\"res_id\":139,\"id\":140},{\"name\":\"LMA_ABC_AD01_1512_00019.pptx\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"ed4278c95beef9acb0f2da93d69e916f\",\"AetnaSize\":599773,\"res_id\":93,\"id\":139},{\"name\":\"LLA_ADS_LC01_1512_00018.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"bf880d2c5f0598c4177839584c95e6b9\",\"AetnaSize\":8313,\"res_id\":137,\"id\":138},{\"name\":\"LLA_ADS_LC01_1512_00018.docx\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"68db1cfb030f189b8e84eb5fc2b7bb51\",\"AetnaSize\":10404,\"res_id\":92,\"id\":137},{\"name\":\"LMA_ABC_AD01_1512_00017.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"601becfab859e1cf2d68ac66d7e164e3\",\"AetnaSize\":392450,\"res_id\":135,\"id\":136},{\"name\":\"LMA_ABC_AD01_1512_00017.docx\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"aa9a95883c6f8f892042af86cf9c9997\",\"AetnaSize\":285650,\"res_id\":91,\"id\":135},{\"name\":\"LMA_ADS_LC01_1512_00016.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"05c6126791e82f13bbb6b1265d8402ad\",\"AetnaSize\":63851,\"res_id\":133,\"id\":134},{\"name\":\"LMA_ADS_LC01_1512_00016\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"bbbaa2ac3c784a2f297474620df6bfb8\",\"AetnaSize\":55782,\"res_id\":90,\"id\":133},{\"name\":\"LMA_ADS_LC01_1512_00015.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"0f657016b14c2323708e4c19291c7681\",\"AetnaSize\":18117,\"res_id\":131,\"id\":132},{\"name\":\"LMA_ADS_LC01_1512_00015\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"665c7569d524b5f0b703e9667514c491\",\"AetnaSize\":4619,\"res_id\":89,\"id\":131},{\"name\":\"LMA_ABC_AD01_1512_00014.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"a3534013609a66266dfa8cd7ddf4d88b\",\"AetnaSize\":92333,\"res_id\":129,\"id\":130},{\"name\":\"LMA_ABC_AD01_1512_00014.docx\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"b4be420af0fcfbd67cab895fd3de626d\",\"AetnaSize\":142186,\"res_id\":88,\"id\":129},{\"name\":\"LMA_ABC_AD01_1512_00013.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"9298e7293f52d9975d7b2d0eee90f6d0\",\"AetnaSize\":91217,\"res_id\":127,\"id\":128},{\"name\":\"LMA_ABC_AD01_1512_00013.docx\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"ab25fdd8191d53d2b0d2f8a85a9f97be\",\"AetnaSize\":346589,\"res_id\":87,\"id\":127},{\"name\":\"OOR_ABC_AD01_1512_00012.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"b0b81d4aabef57376f05e1e50d35cc52\",\"AetnaSize\":61123,\"res_id\":125,\"id\":126},{\"name\":\"OOR_ABC_AD01_1512_00012.xlsx\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"1f97876f0f3f52f7622939c820e9e1da\",\"AetnaSize\":41991,\"res_id\":86,\"id\":125},{\"name\":\"OOR_ADS_LC01_1512_00011.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"4fae4c93b944aa30ecae2ba5bb058318\",\"AetnaSize\":405657,\"res_id\":123,\"id\":124},{\"name\":\"OOR_ADS_LC01_1512_00011.docx\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"8c10d2cff4f3109e7f57ad9ad87d9c25\",\"AetnaSize\":260464,\"res_id\":85,\"id\":123},{\"name\":\"OOR_ADS_LC01_1512_00010.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"c55d3a7fe36ec591be6654f1e3007246\",\"AetnaSize\":391975,\"res_id\":121,\"id\":122},{\"name\":\"OOR_ADS_LC01_1512_00010.docx\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"0e3566c38b641958bca082178fc5cc3e\",\"AetnaSize\":238725,\"res_id\":84,\"id\":121},{\"name\":\"OOR_ABC_AD01_1512_00009.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"dbd738a6e524f233f4f52cfdaf62145b\",\"AetnaSize\":521318,\"res_id\":119,\"id\":120},{\"name\":\"OOR_ABC_AD01_1512_00009.docx\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"2502a2a39ac865e67efc2494123e4d9a\",\"AetnaSize\":1210714,\"res_id\":83,\"id\":119},{\"name\":\"OOR_ADS_LC01_1512_00008.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"2ef5792d2d53784105cd7dae4cb4b4e3\",\"AetnaSize\":562262,\"res_id\":117,\"id\":118},{\"name\":\"OOR_ADS_LC01_1512_00008.pptx\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"5550c5c9fa99a1e06176439d19e27682\",\"AetnaSize\":153384,\"res_id\":82,\"id\":117},{\"name\":\"OOR_ABC_AD01_1512_00007.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"3b5637b746a3e299daff7b974b7a7f6f\",\"AetnaSize\":91111,\"res_id\":115,\"id\":116},{\"name\":\"OOR_ABC_AD01_1512_00007.docx\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"d20173f64915417bd946c51e9747e174\",\"AetnaSize\":346589,\"res_id\":81,\"id\":115},{\"name\":\"test_xls.xlsx\",\"res_model\":\"document.aetna.template\",\"AetnaMd5sum\":false,\"AetnaSize\":0,\"res_id\":11,\"id\":112},{\"name\":\"test_props.docx\",\"res_model\":\"document.aetna.template\",\"AetnaMd5sum\":false,\"AetnaSize\":0,\"res_id\":3,\"id\":111},{\"name\":\"AA00S000N0230.docx\",\"res_model\":\"document.aetna.template\",\"AetnaMd5sum\":false,\"AetnaSize\":0,\"res_id\":10,\"id\":110},{\"name\":\"AA00S000N0090.docx\",\"res_model\":\"document.aetna.template\",\"AetnaMd5sum\":false,\"AetnaSize\":0,\"res_id\":9,\"id\":109},{\"name\":\"AA00S000N0080.docx\",\"res_model\":\"document.aetna.template\",\"AetnaMd5sum\":false,\"AetnaSize\":0,\"res_id\":8,\"id\":108},{\"name\":\"test_ppt.pptx\",\"res_model\":\"document.aetna.template\",\"AetnaMd5sum\":false,\"AetnaSize\":0,\"res_id\":5,\"id\":107},{\"name\":\"AA00S000N0030.docx\",\"res_model\":\"document.aetna.template\",\"AetnaMd5sum\":false,\"AetnaSize\":0,\"res_id\":7,\"id\":106},{\"name\":\"OOR__AD01_1512_00002.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"637343f0ed4cb5ec7a958dfeb40e85de\",\"AetnaSize\":9252,\"res_id\":104,\"id\":105},{\"name\":\"OOR__AD01_1512_00002.docx\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"982d6f2637891ca286a83f02228d4bc2\",\"AetnaSize\":47791,\"res_id\":76,\"id\":104},{\"name\":\"OOR__AD01_1512_00001.pdf\",\"res_model\":\"ir.attachment\",\"AetnaMd5sum\":\"b4f9b4eff2beb91861a3392c8f2ccbde\",\"AetnaSize\":9252,\"res_id\":102,\"id\":103},{\"name\":\"OOR__AD01_1512_00001.docx\",\"res_model\":\"project.task\",\"AetnaMd5sum\":\"281c2934cff7a9c56acfd17c8c9aa5c2\",\"AetnaSize\":11483,\"res_id\":75,\"id\":102},{\"name\":\"/web/js/web.assets_backend/007d2e0\",\"res_model\":false,\"AetnaMd5sum\":false,\"AetnaSize\":0,\"res_id\":0,\"id\":97},{\"name\":\"/web/css/web.assets_backend/007d2e0\",\"res_model\":false,\"AetnaMd5sum\":false,\"AetnaSize\":0,\"res_id\":0,\"id\":96},{\"name\":\"reponse_appel_offre.docx\",\"res_model\":\"document.aetna.template\",\"AetnaMd5sum\":false,\"AetnaSize\":0,\"res_id\":4,\"id\":46},{\"name\":\"/web/js/web.assets_common/ceba8ad\",\"res_model\":false,\"AetnaMd5sum\":false,\"AetnaSize\":0,\"res_id\":0,\"id\":5},{\"name\":\"/web/css/web.assets_common/ceba8ad\",\"res_model\":false,\"AetnaMd5sum\":false,\"AetnaSize\":0,\"res_id\":0,\"id\":3}]'\r\n\r\nvar allItems = JSON.parse(jsonBLOB) ;\r\n\r\ncoll.insert(allItems) ;\r\n\r\nvar results = coll.find({res_model: 'project.task' }) ;\r\nvar resultsNoLoki = allItems.filter(function(item){ \r\n    return item.res_model === 'project.task' ; \r\n}) ;\r\n\r\nlogText(results.length+ \" VS \"+resultsNoLoki.length)\r\nlogObject(results);\r\n\r\n// This statement sends to Inspector\r\ninspectObject(db);\r\n```"},"comment":{"url":"https://api.github.com/repos/techfort/LokiJS/issues/comments/165431144","html_url":"https://github.com/techfort/LokiJS/issues/296#issuecomment-165431144","issue_url":"https://api.github.com/repos/techfort/LokiJS/issues/296","id":165431144,"user":{"login":"obeliskos","id":7353046,"avatar_url":"https://avatars.githubusercontent.com/u/7353046?v=3","gravatar_id":"","url":"https://api.github.com/users/obeliskos","html_url":"https://github.com/obeliskos","followers_url":"https://api.github.com/users/obeliskos/followers","following_url":"https://api.github.com/users/obeliskos/following{/other_user}","gists_url":"https://api.github.com/users/obeliskos/gists{/gist_id}","starred_url":"https://api.github.com/users/obeliskos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/obeliskos/subscriptions","organizations_url":"https://api.github.com/users/obeliskos/orgs","repos_url":"https://api.github.com/users/obeliskos/repos","events_url":"https://api.github.com/users/obeliskos/events{/privacy}","received_events_url":"https://api.github.com/users/obeliskos/received_events","type":"User","site_admin":false},"created_at":"2015-12-17T11:37:28Z","updated_at":"2015-12-17T11:37:28Z","body":"Oh, well thanks for the suggestion.  I did that and it's difficult to say for sure but it looks like it may help a bit.   Hard to guess jit optimizer, but combined checks are the end goal so if anything it will help to ensure that."}}