diff --git a/lib/model.js b/lib/model.js index cec00dc480f..cf8bdfff7fc 100644 --- a/lib/model.js +++ b/lib/model.js @@ -3000,7 +3000,7 @@ Model.create = function create(doc, options, callback) { const last = arguments[arguments.length - 1]; options = {}; // Handle falsy callbacks re: #5061 - if (typeof last === 'function' || !last) { + if (typeof last === 'function' || (arguments.length > 1 && !last)) { cb = last; args = utils.args(arguments, 0, arguments.length - 1); } else { diff --git a/test/model.create.test.js b/test/model.create.test.js index c6097f639de..eb0744d8027 100644 --- a/test/model.create.test.js +++ b/test/model.create.test.js @@ -17,7 +17,7 @@ const DocumentObjectId = mongoose.Types.ObjectId; */ const schema = new Schema({ - title: { type: String, required: true } + title: { type: String } }); describe('model', function() { @@ -187,6 +187,14 @@ describe('model', function() { }). catch(done); }); + + it('treats undefined first arg as doc rather than callback (gh-9765)', function() { + return B.create(void 0). + then(function(doc) { + assert.ok(doc); + assert.ok(doc._id); + }); + }); }); }); });