Skip to content

Commit d69ab22

Browse files
committed
fix(document): support calling Document constructor directly in Node.js
Fix #8237
1 parent 9b986f5 commit d69ab22

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/document.js

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const MongooseError = require('./error/index');
1010
const MixedSchema = require('./schema/mixed');
1111
const ObjectExpectedError = require('./error/objectExpected');
1212
const ObjectParameterError = require('./error/objectParameter');
13+
const Schema = require('./schema');
1314
const StrictModeError = require('./error/strict');
1415
const ValidatorError = require('./schematype').ValidatorError;
1516
const VirtualType = require('./virtualtype');
@@ -64,6 +65,17 @@ function Document(obj, fields, skipId, options) {
6465
}
6566
options = options || {};
6667

68+
// Support `browserDocument.js` syntax
69+
if (this.schema == null) {
70+
const _schema = utils.isObject(fields) && !fields.instanceOfSchema ?
71+
new Schema(fields) :
72+
fields;
73+
this.$__setSchema(_schema);
74+
fields = skipId;
75+
skipId = options;
76+
options = arguments[4] || {};
77+
}
78+
6779
this.$__ = new InternalCache;
6880
this.$__.emitter = new EventEmitter();
6981
this.isNew = 'isNew' in options ? options.isNew : true;

0 commit comments

Comments
 (0)