{"action":"created","issue":{"url":"https://api.github.com/repos/techfort/LokiJS/issues/119","labels_url":"https://api.github.com/repos/techfort/LokiJS/issues/119/labels{/name}","comments_url":"https://api.github.com/repos/techfort/LokiJS/issues/119/comments","events_url":"https://api.github.com/repos/techfort/LokiJS/issues/119/events","html_url":"https://github.com/techfort/LokiJS/issues/119","id":64084337,"number":119,"title":"Unique Index","user":{"login":"jrhicks","id":94417,"avatar_url":"https://avatars.githubusercontent.com/u/94417?v=3","gravatar_id":"","url":"https://api.github.com/users/jrhicks","html_url":"https://github.com/jrhicks","followers_url":"https://api.github.com/users/jrhicks/followers","following_url":"https://api.github.com/users/jrhicks/following{/other_user}","gists_url":"https://api.github.com/users/jrhicks/gists{/gist_id}","starred_url":"https://api.github.com/users/jrhicks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrhicks/subscriptions","organizations_url":"https://api.github.com/users/jrhicks/orgs","repos_url":"https://api.github.com/users/jrhicks/repos","events_url":"https://api.github.com/users/jrhicks/events{/privacy}","received_events_url":"https://api.github.com/users/jrhicks/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-03-24T19:48:32Z","updated_at":"2015-03-24T21:48:33Z","closed_at":null,"body":"I don't think I'm using indexes correclty.\r\n\r\nWhen merging 10,000+ records from a remote database into a local database, I have to use the id (not the $loki id) to make sure the document is not already there.  (if its there I want to merge instead of update).  To do this effeciently, I'm trying to use Loki indices:\r\n\r\n```\r\nlet loki = new Loki('testdb');\r\nmyCollection = loki.addCollection('myCollection', {indices:['id']})\r\n```\r\n\r\nThen on each insert I do\r\n\r\n```\r\nlocalRecord = myCollection.findOne({id: remoteRecord.id})\r\nif( localRecord ) {\r\n  // Merge code\r\n} else {\r\n  myCollection.insert( remoteRecord );  \r\n}\r\n```\r\nWhen I **disable** the localRecord check and just insert, things are smoking fast!  Only slowed by data fetching/paging.\r\n\r\n* http://screencast.com/t/H3wsetchhQ\r\n\r\nWhen I **enable** the findOne check, things slow down a bit:\r\n\r\n* http://screencast.com/t/gBJQ49yBJwW\r\n\r\nWhen I hack an index to the side that is a big hash of ids mapped to $loki I get really fast again.\r\n\r\n* http://screencast.com/t/V5R0g7hPt\r\n\r\nI think there must be something I don't understand about indexes.\r\n\r\nPlease advise :)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/techfort/LokiJS/issues/comments/85707341","html_url":"https://github.com/techfort/LokiJS/issues/119#issuecomment-85707341","issue_url":"https://api.github.com/repos/techfort/LokiJS/issues/119","id":85707341,"user":{"login":"techfort","id":4130173,"avatar_url":"https://avatars.githubusercontent.com/u/4130173?v=3","gravatar_id":"","url":"https://api.github.com/users/techfort","html_url":"https://github.com/techfort","followers_url":"https://api.github.com/users/techfort/followers","following_url":"https://api.github.com/users/techfort/following{/other_user}","gists_url":"https://api.github.com/users/techfort/gists{/gist_id}","starred_url":"https://api.github.com/users/techfort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/techfort/subscriptions","organizations_url":"https://api.github.com/users/techfort/orgs","repos_url":"https://api.github.com/users/techfort/repos","events_url":"https://api.github.com/users/techfort/events{/privacy}","received_events_url":"https://api.github.com/users/techfort/received_events","type":"User","site_admin":false},"created_at":"2015-03-24T21:48:32Z","updated_at":"2015-03-24T21:48:32Z","body":"i'd say we keep it. get(int) will work with $loki, and we could extend get to work like get(var, indexName) => gets a record by index name. Opinions?"}}