diff --git a/lib/document.js b/lib/document.js index 824ac6cf96f..e025207739d 100644 --- a/lib/document.js +++ b/lib/document.js @@ -195,6 +195,10 @@ function Document(obj, fields, skipId, options) { }); } + if (this.modelName === undefined) { + this.modelName = this.constructor.modelName; + } + applyQueue(this); } diff --git a/package.json b/package.json index 48899d57b59..6305e52dd24 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ "release": "git pull && git push origin master --tags && npm publish", "release-legacy": "git pull origin 5.x && git push origin 5.x --tags && npm publish --tag legacy", "mongo": "node ./tools/repl.js", - "test": "mocha --exit ./test/*.test.js", + "test": "mocha --exit --timeout 30000 ./test/*.test.js", "test-rs": "START_REPLICA_SET=1 mocha --timeout 30000 --exit ./test/*.test.js", "test-tsd": "node ./test/types/check-types-filename && tsd", "tdd": "mocha ./test/*.test.js --inspect --watch --recursive --watch-files ./**/*.{js,ts}", diff --git a/test/document.test.js b/test/document.test.js index 1a757bbde32..256f1090f2a 100644 --- a/test/document.test.js +++ b/test/document.test.js @@ -11996,6 +11996,13 @@ describe('document', function() { title: 'The power of JavaScript' }); }); + + it('should apply `modelName` property to new document (gh-12669)', async function() { + const Model = db.model('Test', new Schema()); + + const doc = new Model(); + assert.equal(doc.modelName, 'Test'); + }); }); describe('Check if instance function that is supplied in schema option is availabe', function() {