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