MCPcopy Create free account
hub / github.com/Automattic/mongoose / Document

Function Document

lib/document.js:100–229  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

canSetAdhocKeyFunction · 0.85
defineKeyFunction · 0.85
applyQueueFunction · 0.85

Tested by

no test coverage detected