MCPcopy
hub / github.com/mongodb/node-mongodb-native / transformDocument

Function transformDocument

src/cursor/abstract_cursor.ts:1072–1092  ·  view source on GitHub ↗

@internal

(document: NonNullable<TSchema>)

Source from the content-addressed store, hash-verified

1070
1071 /** @internal */
1072 private async transformDocument(document: NonNullable<TSchema>): Promise<NonNullable<TSchema>> {
1073 if (this.transform == null) return document;
1074
1075 try {
1076 const transformedDocument = this.transform(document);
1077 // eslint-disable-next-line no-restricted-syntax
1078 if (transformedDocument === null) {
1079 const TRANSFORM_TO_NULL_ERROR =
1080 'Cursor returned a `null` document, but the cursor is not exhausted. Mapping documents to `null` is not supported in the cursor transform.';
1081 throw new MongoAPIError(TRANSFORM_TO_NULL_ERROR);
1082 }
1083 return transformedDocument;
1084 } catch (transformError) {
1085 try {
1086 await this.close();
1087 } catch (closeError) {
1088 squashError(closeError);
1089 }
1090 throw transformError;
1091 }
1092 }
1093
1094 /** @internal */
1095 protected throwIfInitialized() {

Callers

nothing calls this directly

Calls 2

squashErrorFunction · 0.90
closeMethod · 0.45

Tested by

no test coverage detected