* 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, options)
| 88 | */ |
| 89 | |
| 90 | function Document(obj, fields, options) { |
| 91 | if (typeof options === 'boolean') { |
| 92 | throw new Error('The skipId parameter has been removed. Use { skipId: true } in the options parameter instead.'); |
| 93 | } |
| 94 | options = Object.assign({}, options); |
| 95 | let skipId = options.skipId; |
| 96 | |
| 97 | this.$__ = new InternalCache(); |
| 98 | |
| 99 | // Support `browserDocument.js` syntax |
| 100 | if (this.$__schema == null) { |
| 101 | const _schema = utils.isObject(fields) && !fields.instanceOfSchema ? |
| 102 | new Schema(fields) : |
| 103 | fields; |
| 104 | |
| 105 | this.$__setSchema(_schema); |
| 106 | fields = options; |
| 107 | skipId = options.skipId; |
| 108 | } |
| 109 | |
| 110 | // Avoid setting `isNew` to `true`, because it is `true` by default |
| 111 | if (options.isNew != null && options.isNew !== true) { |
| 112 | this.$isNew = options.isNew; |
| 113 | } |
| 114 | |
| 115 | if (options.priorDoc != null) { |
| 116 | this.$__.priorDoc = options.priorDoc; |
| 117 | } |
| 118 | |
| 119 | if (skipId) { |
| 120 | this.$__.skipId = skipId; |
| 121 | } |
| 122 | |
| 123 | if (obj != null && typeof obj !== 'object') { |
| 124 | throw new ObjectParameterError(obj, 'obj', 'Document'); |
| 125 | } |
| 126 | |
| 127 | let defaults = true; |
| 128 | if (options.defaults !== undefined) { |
| 129 | this.$__.defaults = options.defaults; |
| 130 | defaults = options.defaults; |
| 131 | } |
| 132 | |
| 133 | const schema = this.$__schema; |
| 134 | |
| 135 | if (typeof fields === 'boolean' || fields === 'throw') { |
| 136 | if (fields !== true) { |
| 137 | this.$__.strictMode = fields; |
| 138 | } |
| 139 | fields = undefined; |
| 140 | } else if (options.strict !== undefined) { |
| 141 | this.$__.strictMode = options.strict; |
| 142 | } else if (schema.options.strict !== true) { |
| 143 | this.$__.strictMode = schema.options.strict; |
| 144 | } |
| 145 | |
| 146 | const requiredPaths = schema.requiredPaths(); |
| 147 | for (const path of requiredPaths) { |
nothing calls this directly
no test coverage detected