{"action":"closed","issue":{"url":"https://api.github.com/repos/cheeriojs/cheerio/issues/752","labels_url":"https://api.github.com/repos/cheeriojs/cheerio/issues/752/labels{/name}","comments_url":"https://api.github.com/repos/cheeriojs/cheerio/issues/752/comments","events_url":"https://api.github.com/repos/cheeriojs/cheerio/issues/752/events","html_url":"https://github.com/cheeriojs/cheerio/issues/752","id":106778554,"number":752,"title":"async function in the $.each callbacks","user":{"login":"chenweiyj","id":1733948,"avatar_url":"https://avatars.githubusercontent.com/u/1733948?v=3","gravatar_id":"","url":"https://api.github.com/users/chenweiyj","html_url":"https://github.com/chenweiyj","followers_url":"https://api.github.com/users/chenweiyj/followers","following_url":"https://api.github.com/users/chenweiyj/following{/other_user}","gists_url":"https://api.github.com/users/chenweiyj/gists{/gist_id}","starred_url":"https://api.github.com/users/chenweiyj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chenweiyj/subscriptions","organizations_url":"https://api.github.com/users/chenweiyj/orgs","repos_url":"https://api.github.com/users/chenweiyj/repos","events_url":"https://api.github.com/users/chenweiyj/events{/privacy}","received_events_url":"https://api.github.com/users/chenweiyj/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-16T13:54:27Z","updated_at":"2015-09-22T13:48:38Z","closed_at":"2015-09-22T13:48:38Z","body":"I have following code in my node script.\r\n\r\n```\r\n$('p').each(function (idx, elem) {\r\n  var article = new Article({content: $(this).html()});\r\n  article.save(function (err) {// do something}); // db save async function or other async function\r\n});\r\n\r\nmongoose.connection.close();\r\n```\r\n\r\nHowever, the `mongoose.connection.close()` will run before all the documents are saved to the database. So how can I make sure all things are done before closing the db connection?\r\n"}}