Skip to content

Commit

Permalink
fix(document): support calling Document constructor directly in Nod…
Browse files Browse the repository at this point in the history
…e.js

Fix #8237
  • Loading branch information
vkarpov15 committed Oct 20, 2019
1 parent 9b986f5 commit d69ab22
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/document.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d69ab22

Please sign in to comment.