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

Function _resetSessionDocuments

lib/connection.js:772–802  ·  view source on GitHub ↗
(session)

Source from the content-addressed store, hash-verified

770 * If transaction was aborted, we need to reset newly inserted documents' `isNew`.
771 */
772function _resetSessionDocuments(session) {
773 for (const doc of session[sessionNewDocuments].keys()) {
774 const state = session[sessionNewDocuments].get(doc);
775 if (Object.hasOwn(state, 'isNew')) {
776 doc.$isNew = state.isNew;
777 }
778 if (Object.hasOwn(state, 'versionKey')) {
779 doc.set(doc.schema.options.versionKey, state.versionKey);
780 }
781
782 if (state.modifiedPaths.length > 0 && doc.$__.activePaths.states.modify == null) {
783 doc.$__.activePaths.states.modify = {};
784 }
785 for (const path of state.modifiedPaths) {
786 const currentState = doc.$__.activePaths.paths[path];
787 if (currentState != null) {
788 delete doc.$__.activePaths[currentState][path];
789 }
790 doc.$__.activePaths.paths[path] = 'modify';
791 doc.$__.activePaths.states.modify[path] = true;
792 }
793
794 for (const path of state.atomics.keys()) {
795 const val = doc.$__getValue(path);
796 if (val == null) {
797 continue;
798 }
799 val[arrayAtomicsSymbol] = state.atomics.get(path);
800 }
801 }
802}
803
804/**
805 * Helper for `dropCollection()`. Will delete the given collection, including

Callers 1

_wrapUserTransactionFunction · 0.85

Calls 2

getMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…