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

Function Document

lib/document.js:92–215  ·  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 query

(obj, fields, options)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

defineKeyFunction · 0.85
applyQueueFunction · 0.85

Tested by

no test coverage detected