{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/4507","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/4507/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/4507/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/4507/events","html_url":"https://github.com/Automattic/mongoose/issues/4507","id":176280984,"number":4507,"title":"when i need close mongoose connection?","user":{"login":"wjx0912","id":5556482,"avatar_url":"https://avatars.githubusercontent.com/u/5556482?v=3","gravatar_id":"","url":"https://api.github.com/users/wjx0912","html_url":"https://github.com/wjx0912","followers_url":"https://api.github.com/users/wjx0912/followers","following_url":"https://api.github.com/users/wjx0912/following{/other_user}","gists_url":"https://api.github.com/users/wjx0912/gists{/gist_id}","starred_url":"https://api.github.com/users/wjx0912/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wjx0912/subscriptions","organizations_url":"https://api.github.com/users/wjx0912/orgs","repos_url":"https://api.github.com/users/wjx0912/repos","events_url":"https://api.github.com/users/wjx0912/events{/privacy}","received_events_url":"https://api.github.com/users/wjx0912/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Automattic/mongoose/labels/help","name":"help","color":"FFFFFF"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-09-12T02:08:15Z","updated_at":"2016-10-05T23:20:23Z","closed_at":null,"body":"my work flow is: connect,  {insert, query, insert, query, etc...}, close\r\nmy question is after all work done, i wan't close mongoose, so process 'node.js' exit.\r\ncurrent solution is after 'insert/query', i call setTimeout(5 second) and close in callback.\r\n\r\n\r\n(1) after all 'insert/query', is some callback run?\r\n(2) is a function 'set_workqueue_empty_callback' exit?\r\n\r\nthanks"},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/251827373","html_url":"https://github.com/Automattic/mongoose/issues/4507#issuecomment-251827373","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/4507","id":251827373,"user":{"login":"zbjornson","id":469365,"avatar_url":"https://avatars.githubusercontent.com/u/469365?v=3","gravatar_id":"","url":"https://api.github.com/users/zbjornson","html_url":"https://github.com/zbjornson","followers_url":"https://api.github.com/users/zbjornson/followers","following_url":"https://api.github.com/users/zbjornson/following{/other_user}","gists_url":"https://api.github.com/users/zbjornson/gists{/gist_id}","starred_url":"https://api.github.com/users/zbjornson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zbjornson/subscriptions","organizations_url":"https://api.github.com/users/zbjornson/orgs","repos_url":"https://api.github.com/users/zbjornson/repos","events_url":"https://api.github.com/users/zbjornson/events{/privacy}","received_events_url":"https://api.github.com/users/zbjornson/received_events","type":"User","site_admin":false},"created_at":"2016-10-05T23:20:23Z","updated_at":"2016-10-05T23:20:23Z","body":"@vkarpov15 I think what wjx0912 is trying to ask is this: Mongoose/mongodb normally keeps a strong reference to the database connection, which prevents the node process from exiting. How do you let node.js exit after e.g. all queries are done?\r\n\r\n@wjx0912 does this work for you?\r\n```js\r\nvar mongoose = require(\"mongoose\");\r\nvar connection = mongoose.connect(\"...\");\r\nconnection.connections.forEach(function (conn) {\r\n  conn.db.unref(); // make database connection weak, so it won't block process from exiting\r\n});\r\n```\r\n"}}
{"actor":{"display_login":"zbjornson"}}