{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/6228","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/6228/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/6228/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/6228/events","html_url":"https://github.com/Automattic/mongoose/issues/6228","id":303911986,"number":6228,"title":"insertMany() error handling middleware does not work","user":{"login":"williamdang","id":11851885,"avatar_url":"https://avatars0.githubusercontent.com/u/11851885?v=4","gravatar_id":"","url":"https://api.github.com/users/williamdang","html_url":"https://github.com/williamdang","followers_url":"https://api.github.com/users/williamdang/followers","following_url":"https://api.github.com/users/williamdang/following{/other_user}","gists_url":"https://api.github.com/users/williamdang/gists{/gist_id}","starred_url":"https://api.github.com/users/williamdang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/williamdang/subscriptions","organizations_url":"https://api.github.com/users/williamdang/orgs","repos_url":"https://api.github.com/users/williamdang/repos","events_url":"https://api.github.com/users/williamdang/events{/privacy}","received_events_url":"https://api.github.com/users/williamdang/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/Automattic/mongoose/milestones/217","html_url":"https://github.com/Automattic/mongoose/milestone/217","labels_url":"https://api.github.com/repos/Automattic/mongoose/milestones/217/labels","id":3182263,"number":217,"title":"5.0.12","description":"","creator":{"login":"vkarpov15","id":1620265,"avatar_url":"https://avatars2.githubusercontent.com/u/1620265?v=4","gravatar_id":"","url":"https://api.github.com/users/vkarpov15","html_url":"https://github.com/vkarpov15","followers_url":"https://api.github.com/users/vkarpov15/followers","following_url":"https://api.github.com/users/vkarpov15/following{/other_user}","gists_url":"https://api.github.com/users/vkarpov15/gists{/gist_id}","starred_url":"https://api.github.com/users/vkarpov15/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkarpov15/subscriptions","organizations_url":"https://api.github.com/users/vkarpov15/orgs","repos_url":"https://api.github.com/users/vkarpov15/repos","events_url":"https://api.github.com/users/vkarpov15/events{/privacy}","received_events_url":"https://api.github.com/users/vkarpov15/received_events","type":"User","site_admin":false},"open_issues":9,"closed_issues":1,"state":"open","created_at":"2018-03-12T23:58:04Z","updated_at":"2018-03-20T18:09:56Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2018-03-09T17:06:17Z","updated_at":"2018-03-20T18:10:18Z","closed_at":"2018-03-20T18:09:56Z","author_association":"NONE","body":"<!-- *Before creating an issue please make sure you are using the latest version of mongoose -->\r\n\r\n**Do you want to request a *feature* or report a *bug*?**\r\nI want to report a bug\r\n\r\n**What is the current behavior?**\r\nThe error handling middleware for `insertMany()` does not work.\r\n\r\n**If the current behavior is a bug, please provide the steps to reproduce.**\r\nHere is a script to reproduce the problem:\r\n\r\n    const Mongoose = require('mongoose');\r\n    const Schema = Mongoose.Schema;\r\n    const expect = require('expect.js');\r\n    \r\n    describe('Mongoose', function () {\r\n      Mongoose.Promise = global.Promise;\r\n      \r\n      let canHookPostInsertMany = false;\r\n      let canHookPostInsertManyError = false;\r\n      \r\n      const fooSchema = new Schema({\r\n        foo: {type: String},\r\n      });\r\n      \r\n      fooSchema.index({foo: 1}, {unique: true});\r\n      \r\n      fooSchema.post('insertMany', (doc, next) => {\r\n        canHookPostInsertMany = true;\r\n        next();\r\n      });\r\n      \r\n      fooSchema.post('insertMany', (err, doc, next) => {\r\n        canHookPostInsertManyError = true;\r\n        next(err);\r\n      });\r\n      \r\n      const Foo = Mongoose.model('Foo', fooSchema);\r\n      \r\n      before(async function () {\r\n        await Mongoose.connect('mongodb://localhost/test');\r\n        \r\n        await Foo.remove().exec();\r\n      });\r\n      \r\n      after(async function () {\r\n        await Foo.remove().exec();\r\n      });\r\n      \r\n      describe('duplicate insertMany()', function () {\r\n        it('should turn on \"canHookPostInsertMany\" and \"canHookPostInsertManyError\"', async function () {\r\n          try {\r\n            const foos = await Foo.insertMany([\r\n              {foo: 'duplicated'},\r\n              {foo: 'duplicated'},\r\n            ]);\r\n          } catch (e) {\r\n          }\r\n          \r\n          expect(canHookPostInsertMany).to.be(true);\r\n          expect(canHookPostInsertManyError).to.be(true);\r\n        });\r\n      });\r\n    });\r\n\r\n**What is the expected behavior?**\r\nThe post \"insertMany()\" hook for error handling should work. \r\n\r\n**Please mention your node.js, mongoose and MongoDB version.**\r\nI am using node.js 8.9.4, mongoose 5.0.9 and MongoDb 3.6.3"},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/374701232","html_url":"https://github.com/Automattic/mongoose/issues/6228#issuecomment-374701232","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/6228","id":374701232,"user":{"login":"vkarpov15","id":1620265,"avatar_url":"https://avatars2.githubusercontent.com/u/1620265?v=4","gravatar_id":"","url":"https://api.github.com/users/vkarpov15","html_url":"https://github.com/vkarpov15","followers_url":"https://api.github.com/users/vkarpov15/followers","following_url":"https://api.github.com/users/vkarpov15/following{/other_user}","gists_url":"https://api.github.com/users/vkarpov15/gists{/gist_id}","starred_url":"https://api.github.com/users/vkarpov15/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkarpov15/subscriptions","organizations_url":"https://api.github.com/users/vkarpov15/orgs","repos_url":"https://api.github.com/users/vkarpov15/repos","events_url":"https://api.github.com/users/vkarpov15/events{/privacy}","received_events_url":"https://api.github.com/users/vkarpov15/received_events","type":"User","site_admin":false},"created_at":"2018-03-20T18:10:18Z","updated_at":"2018-03-20T18:10:18Z","author_association":"COLLABORATOR","body":"Thanks for your patience, fixed in master and fix will be in 5.0.12 :+1: "}}
{"actor":{"display_login":"vkarpov15"}}