{"action":"reopened","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/4482","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/4482/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/4482/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/4482/events","html_url":"https://github.com/Automattic/mongoose/issues/4482","id":174856753,"number":4482,"title":"Unhandled Reject Write Error on compound unique index duplicate.","user":{"login":"r3wt","id":4483325,"avatar_url":"https://avatars.githubusercontent.com/u/4483325?v=3","gravatar_id":"","url":"https://api.github.com/users/r3wt","html_url":"https://github.com/r3wt","followers_url":"https://api.github.com/users/r3wt/followers","following_url":"https://api.github.com/users/r3wt/following{/other_user}","gists_url":"https://api.github.com/users/r3wt/gists{/gist_id}","starred_url":"https://api.github.com/users/r3wt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/r3wt/subscriptions","organizations_url":"https://api.github.com/users/r3wt/orgs","repos_url":"https://api.github.com/users/r3wt/repos","events_url":"https://api.github.com/users/r3wt/events{/privacy}","received_events_url":"https://api.github.com/users/r3wt/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":4,"created_at":"2016-09-02T22:07:52Z","updated_at":"2016-09-22T23:50:29Z","closed_at":null,"body":"**Expected behavior:**\r\n\r\nexception is caught and provided to callback as `err` parameter.\r\n\r\n**Actual behavior:**\r\n\r\nexception is not caught, result in stack unwind and app explodes needlessly.\r\n\r\n**model:**\r\n```js\r\nvar mongoose = require('mongoose');\r\nvar Schema = mongoose.Schema;\r\nvar Types = Schema.Types;\r\n\r\nvar CheckinsSchema = new Schema({\r\n\tuser: {\r\n\t\ttype: Types.ObjectId, ref: 'User', index: true //invited user\r\n\t},\r\n\tevent: {\r\n\t\ttype: Types.ObjectId, ref: 'Event', index: true\r\n\t},\r\n\ttenant: { \r\n\t\ttype: Types.ObjectId, ref: 'Tenant', index: true \r\n\t},\r\n\tcheckInTime: { \r\n\t\ttype: Types.Date, default: null \r\n\t}\r\n});\r\n\r\nCheckinsSchema.index({ user: 1, event: 1, tenant: 1}, { unique: true });\r\n\r\nmodule.exports = Checkins = mongoose.model('Checkins', CheckinsSchema);\r\n```\r\n**request handler:**\r\n```js\r\nfunction checkIn(req,res){\r\n\tvar id = req.params.id;\r\n\t\r\n\tvar m = new model.Checkins({\r\n\t\tevent: id,\r\n\t\tuser: req.user.id,\r\n\t\ttenant: req.tenant,\r\n\t\tcheckInTime: new Date(Date.now()) \r\n\t});\r\n\t\r\n\tm.save(function(err,insert){\r\n\t\t\r\n\t\tif(err) return res.error('already checked in');\r\n\t\tres.apiResponse('ok');\r\n\t\t\r\n\t});\t\r\n}\r\n```"}}
{"actor":{"display_login":"vkarpov15"}}