MCPcopy
hub / github.com/Automattic/mongoose / completeOne

Function completeOne

lib/query.js:3366–3396  ·  view source on GitHub ↗

* hydrates a document * * @param {Model} model * @param {Document} doc * @param {object} res 3rd parameter to callback * @param {object} fields * @param {Query} self * @param {Array} [pop] array of paths used in population * @param {Function} callback * @api private

(model, doc, res, options, fields, userProvidedFields, pop, callback)

Source from the content-addressed store, hash-verified

3364 */
3365
3366function completeOne(model, doc, res, options, fields, userProvidedFields, pop, callback) {
3367 if (options.includeResultMetadata && doc == null) {
3368 _init(null);
3369 return null;
3370 }
3371
3372 helpers.createModelAndInit(model, doc, fields, userProvidedFields, options, pop, _init);
3373
3374 function _init(err, casted) {
3375 if (err) {
3376 return callback(err);
3377 }
3378
3379
3380 if (options.includeResultMetadata) {
3381 if (doc && casted) {
3382 if (options.session != null) {
3383 casted.$session(options.session);
3384 }
3385 res.value = casted;
3386 } else {
3387 res.value = null;
3388 }
3389 return callback(null, res);
3390 }
3391 if (options.session != null) {
3392 casted.$session(options.session);
3393 }
3394 callback(null, casted);
3395 }
3396}
3397
3398/**
3399 * If the model is a discriminator type and not root, then add the key & value to the criteria.

Callers 1

query.jsFile · 0.85

Calls 1

_initFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…