* The core Mongoose document constructor. You should not call this directly, * the Mongoose [Model constructor](./api/model.html#Model) calls this for you. * * @param {Object} obj the values to set * @param {Object} [fields] optional object containing the fields which were selected in the query
(obj, fields, skipId, options)
| 79 | */ |
| 80 | |
| 81 | function Document(obj, fields, skipId, options) { |
| 82 | if (typeof skipId === 'object' && skipId != null) { |
| 83 | options = skipId; |
| 84 | skipId = options.skipId; |
| 85 | } |
| 86 | options = Object.assign({}, options); |
| 87 | |
| 88 | // Support `browserDocument.js` syntax |
| 89 | if (this.$__schema == null) { |
| 90 | const _schema = utils.isObject(fields) && !fields.instanceOfSchema ? |
| 91 | new Schema(fields) : |
| 92 | fields; |
| 93 | this.$__setSchema(_schema); |
| 94 | fields = skipId; |
| 95 | skipId = options; |
| 96 | options = arguments[4] || {}; |
| 97 | } |
| 98 | |
| 99 | this.$__ = new InternalCache(); |
| 100 | |
| 101 | // Avoid setting `isNew` to `true`, because it is `true` by default |
| 102 | if (options.isNew != null && options.isNew !== true) { |
| 103 | this.$isNew = options.isNew; |
| 104 | } |
| 105 | |
| 106 | if (options.priorDoc != null) { |
| 107 | this.$__.priorDoc = options.priorDoc; |
| 108 | } |
| 109 | |
| 110 | if (skipId) { |
| 111 | this.$__.skipId = skipId; |
| 112 | } |
| 113 | |
| 114 | if (obj != null && typeof obj !== 'object') { |
| 115 | throw new ObjectParameterError(obj, 'obj', 'Document'); |
| 116 | } |
| 117 | |
| 118 | let defaults = true; |
| 119 | if (options.defaults !== undefined) { |
| 120 | this.$__.defaults = options.defaults; |
| 121 | defaults = options.defaults; |
| 122 | } |
| 123 | |
| 124 | const schema = this.$__schema; |
| 125 | |
| 126 | if (typeof fields === 'boolean' || fields === 'throw') { |
| 127 | if (fields !== true) { |
| 128 | this.$__.strictMode = fields; |
| 129 | } |
| 130 | fields = undefined; |
| 131 | } else if (schema.options.strict !== true) { |
| 132 | this.$__.strictMode = schema.options.strict; |
| 133 | } |
| 134 | |
| 135 | const requiredPaths = schema.requiredPaths(true); |
| 136 | for (const path of requiredPaths) { |
| 137 | this.$__.activePaths.require(path); |
| 138 | } |
nothing calls this directly
no test coverage detected