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

Function _createSaveOptions

lib/model.js:338–378  ·  view source on GitHub ↗
(doc, options)

Source from the content-addressed store, hash-verified

336 * ignore
337 */
338function _createSaveOptions(doc, options) {
339 const saveOptions = {};
340
341 applyWriteConcern(doc.$__schema, options);
342 if (typeof options.writeConcern !== 'undefined') {
343 saveOptions.writeConcern = {};
344 if ('w' in options.writeConcern) {
345 saveOptions.writeConcern.w = options.writeConcern.w;
346 }
347 if ('j' in options.writeConcern) {
348 saveOptions.writeConcern.j = options.writeConcern.j;
349 }
350 if ('wtimeout' in options.writeConcern) {
351 saveOptions.writeConcern.wtimeout = options.writeConcern.wtimeout;
352 }
353 } else {
354 if ('w' in options) {
355 saveOptions.w = options.w;
356 }
357 if ('j' in options) {
358 saveOptions.j = options.j;
359 }
360 if ('wtimeout' in options) {
361 saveOptions.wtimeout = options.wtimeout;
362 }
363 }
364 if ('checkKeys' in options) {
365 saveOptions.checkKeys = options.checkKeys;
366 }
367
368 const session = doc.$session();
369 const asyncLocalStorage = doc[modelDbSymbol].base.transactionAsyncLocalStorage?.getStore();
370 if (session != null) {
371 saveOptions.session = session;
372 } else if (!Object.hasOwn(options, 'session') && asyncLocalStorage?.session != null) {
373 // Only set session from asyncLocalStorage if `session` option wasn't originally passed in options
374 saveOptions.session = asyncLocalStorage.session;
375 }
376
377 return saveOptions;
378}
379
380/*!
381 * ignore

Callers 1

model.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…