{"action":"created","issue":{"url":"https://api.github.com/repos/techfort/LokiJS/issues/60","repository_url":"https://api.github.com/repos/techfort/LokiJS","labels_url":"https://api.github.com/repos/techfort/LokiJS/issues/60/labels{/name}","comments_url":"https://api.github.com/repos/techfort/LokiJS/issues/60/comments","events_url":"https://api.github.com/repos/techfort/LokiJS/issues/60/events","html_url":"https://github.com/techfort/LokiJS/issues/60","id":54181017,"number":60,"title":"db save circular structure issue","user":{"login":"teef","id":4948545,"avatar_url":"https://avatars.githubusercontent.com/u/4948545?v=3","gravatar_id":"","url":"https://api.github.com/users/teef","html_url":"https://github.com/teef","followers_url":"https://api.github.com/users/teef/followers","following_url":"https://api.github.com/users/teef/following{/other_user}","gists_url":"https://api.github.com/users/teef/gists{/gist_id}","starred_url":"https://api.github.com/users/teef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teef/subscriptions","organizations_url":"https://api.github.com/users/teef/orgs","repos_url":"https://api.github.com/users/teef/repos","events_url":"https://api.github.com/users/teef/events{/privacy}","received_events_url":"https://api.github.com/users/teef/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":36,"created_at":"2015-01-13T11:29:22Z","updated_at":"2016-04-01T00:59:39Z","closed_at":"2015-01-20T12:59:06Z","body":"Currently I have a problem in the area of loading/saving database. After object update and try to save db the following error occurs:\r\n```javascript\r\nstream.js:94\r\n      throw er; // Unhandled stream error in pipe.\r\n            ^\r\nTypeError: Converting circular structure to JSON\r\n    at Object.stringify (native)\r\n    at LokiEventEmitter.Loki.serialize (/home/teef/leonardo/WebApplications/Leonardo-CommHub/node_modules/lokijs/src/lokijs.js:385:19)\r\n    at LokiEventEmitter.Loki.saveDatabase (/home/teef/leonardo/WebApplications/Leonardo-CommHub/node_modules/lokijs/src/lokijs.js:744:47)\r\n```\r\nI am using one collection as well as one dynamic view.\r\n\r\nSeems like there are two dynamic views which should not happen.\r\n\r\n```javascript\r\nDynamicViews: \r\n   [ { collection: [Circular],\r\n       name: 'aciveDevices',\r\n       persistent: false,\r\n       resultset: [Object],\r\n       resultdata: [],\r\n       resultsdirty: true,\r\n       cachedresultset: null,\r\n       filterPipeline: [],\r\n       sortFunction: null,\r\n       sortCriteria: null,\r\n       sortDirty: false,\r\n       events: [Object] },\r\n     { collection: [Circular],\r\n       name: 'aciveDevices',\r\n       persistent: false,\r\n       resultset: [Object],\r\n       resultdata: [],\r\n       resultsdirty: false,\r\n       cachedresultset: null,\r\n       filterPipeline: [Object],\r\n       sortFunction: null,\r\n       sortCriteria: null,\r\n       sortDirty: false,\r\n       events: [Object] } ],\r\n```\r\n\r\nDatabase: https://gist.github.com/teef/c3f8f2139a1e13188e09"},"comment":{"url":"https://api.github.com/repos/techfort/LokiJS/issues/comments/204195413","html_url":"https://github.com/techfort/LokiJS/issues/60#issuecomment-204195413","issue_url":"https://api.github.com/repos/techfort/LokiJS/issues/60","id":204195413,"user":{"login":"rockneverdies55","id":4588562,"avatar_url":"https://avatars.githubusercontent.com/u/4588562?v=3","gravatar_id":"","url":"https://api.github.com/users/rockneverdies55","html_url":"https://github.com/rockneverdies55","followers_url":"https://api.github.com/users/rockneverdies55/followers","following_url":"https://api.github.com/users/rockneverdies55/following{/other_user}","gists_url":"https://api.github.com/users/rockneverdies55/gists{/gist_id}","starred_url":"https://api.github.com/users/rockneverdies55/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rockneverdies55/subscriptions","organizations_url":"https://api.github.com/users/rockneverdies55/orgs","repos_url":"https://api.github.com/users/rockneverdies55/repos","events_url":"https://api.github.com/users/rockneverdies55/events{/privacy}","received_events_url":"https://api.github.com/users/rockneverdies55/received_events","type":"User","site_admin":false},"created_at":"2016-04-01T00:59:39Z","updated_at":"2016-04-01T00:59:39Z","body":"Just putting here as a reference in the case if people come here from a google search...\r\n\r\nI had a similar issue because of using underscore extend function. Something like the following was causing the issue:\r\n\r\n```\r\nvar settings = require('../settings.js');\r\n\r\nvar settingsCOL = db.addCollection('settings');\r\nsettingsCOL.insert(_.extend({title: 'appSettings'}, settings));\r\n\r\n```"}}