diff --git a/lib/document.js b/lib/document.js index c725b2083ab..e108d55679c 100644 --- a/lib/document.js +++ b/lib/document.js @@ -10,6 +10,7 @@ const MongooseError = require('./error/index'); const MixedSchema = require('./schema/mixed'); const ObjectExpectedError = require('./error/objectExpected'); const ObjectParameterError = require('./error/objectParameter'); +const Schema = require('./schema'); const StrictModeError = require('./error/strict'); const ValidatorError = require('./schematype').ValidatorError; const VirtualType = require('./virtualtype'); @@ -64,6 +65,17 @@ function Document(obj, fields, skipId, options) { } options = options || {}; + // Support `browserDocument.js` syntax + if (this.schema == null) { + const _schema = utils.isObject(fields) && !fields.instanceOfSchema ? + new Schema(fields) : + fields; + this.$__setSchema(_schema); + fields = skipId; + skipId = options; + options = arguments[4] || {}; + } + this.$__ = new InternalCache; this.$__.emitter = new EventEmitter(); this.isNew = 'isNew' in options ? options.isNew : true;