@@ -938,7 +938,8 @@ export class MongoStorageAdapter implements StorageAdapter {
938938 hint : ?mixed ,
939939 explain ? : boolean ,
940940 comment : ?string ,
941- rawValues ? : boolean
941+ rawValues ? : boolean ,
942+ rawFieldNames ? : boolean
942943 ) {
943944 validateExplainValue ( explain ) ;
944945 if ( rawValues ) {
@@ -947,7 +948,7 @@ export class MongoStorageAdapter implements StorageAdapter {
947948 let isPointerField = false ;
948949 pipeline = pipeline . map ( stage => {
949950 if ( stage . $group ) {
950- stage . $group = this . _parseAggregateGroupArgs ( schema , stage . $group ) ;
951+ stage . $group = this . _parseAggregateGroupArgs ( schema , stage . $group , rawFieldNames ) ;
951952 if (
952953 stage . $group . _id &&
953954 typeof stage . $group . _id === 'string' &&
@@ -957,13 +958,13 @@ export class MongoStorageAdapter implements StorageAdapter {
957958 }
958959 }
959960 if ( stage . $match ) {
960- stage . $match = this . _parseAggregateArgs ( schema , stage . $match , rawValues ) ;
961+ stage . $match = this . _parseAggregateArgs ( schema , stage . $match , rawValues , rawFieldNames ) ;
961962 }
962963 if ( stage . $project ) {
963- stage . $project = this . _parseAggregateProjectArgs ( schema , stage . $project ) ;
964+ stage . $project = this . _parseAggregateProjectArgs ( schema , stage . $project , rawValues , rawFieldNames ) ;
964965 }
965966 if ( stage . $geoNear && stage . $geoNear . query ) {
966- stage . $geoNear . query = this . _parseAggregateArgs ( schema , stage . $geoNear . query , rawValues ) ;
967+ stage . $geoNear . query = this . _parseAggregateArgs ( schema , stage . $geoNear . query , rawValues , rawFieldNames ) ;
967968 }
968969 return stage ;
969970 } ) ;
@@ -980,7 +981,7 @@ export class MongoStorageAdapter implements StorageAdapter {
980981 } )
981982 )
982983 . then ( results => {
983- if ( rawValues ) {
984+ if ( rawFieldNames ) {
984985 return results ;
985986 }
986987 results . forEach ( result => {
@@ -1005,6 +1006,9 @@ export class MongoStorageAdapter implements StorageAdapter {
10051006 if ( rawValues ) {
10061007 return objects . map ( obj => EJSON . serialize ( obj ) ) ;
10071008 }
1009+ if ( rawFieldNames ) {
1010+ return objects ;
1011+ }
10081012 return objects . map ( object => mongoObjectToParseObject ( className , object , schema ) ) ;
10091013 } )
10101014 . catch ( err => this . handleError ( err ) ) ;
@@ -1029,17 +1033,17 @@ export class MongoStorageAdapter implements StorageAdapter {
10291033 //
10301034 // As much as I hate recursion...this seemed like a good fit for it. We're essentially traversing
10311035 // down a tree to find a "leaf node" and checking to see if it needs to be converted.
1032- _parseAggregateArgs ( schema : any , pipeline : any , rawValues ? : boolean ) : any {
1036+ _parseAggregateArgs ( schema : any , pipeline : any , rawValues ? : boolean , rawFieldNames ? : boolean ) : any {
10331037 if ( pipeline === null ) {
10341038 return null ;
10351039 } else if ( Utils . isDate ( pipeline ) ) {
10361040 return pipeline ;
10371041 } else if ( Array . isArray ( pipeline ) ) {
1038- return pipeline . map ( value => this . _parseAggregateArgs ( schema , value , rawValues ) ) ;
1042+ return pipeline . map ( value => this . _parseAggregateArgs ( schema , value , rawValues , rawFieldNames ) ) ;
10391043 } else if ( typeof pipeline === 'object' ) {
10401044 const returnValue = { } ;
10411045 for ( const field in pipeline ) {
1042- if ( schema . fields [ field ] && schema . fields [ field ] . type === 'Pointer' ) {
1046+ if ( ! rawFieldNames && schema . fields [ field ] && schema . fields [ field ] . type === 'Pointer' ) {
10431047 if ( typeof pipeline [ field ] === 'object' ) {
10441048 returnValue [ `_p_${ field } ` ] = pipeline [ field ] ;
10451049 } else if ( rawValues ) {
@@ -1050,18 +1054,20 @@ export class MongoStorageAdapter implements StorageAdapter {
10501054 } else if ( schema . fields [ field ] && schema . fields [ field ] . type === 'Date' && ! rawValues ) {
10511055 returnValue [ field ] = this . _convertToDate ( pipeline [ field ] ) ;
10521056 } else {
1053- returnValue [ field ] = this . _parseAggregateArgs ( schema , pipeline [ field ] , rawValues ) ;
1057+ returnValue [ field ] = this . _parseAggregateArgs ( schema , pipeline [ field ] , rawValues , rawFieldNames ) ;
10541058 }
10551059
1056- if ( field === 'objectId' ) {
1057- returnValue [ '_id' ] = returnValue [ field ] ;
1058- delete returnValue [ field ] ;
1059- } else if ( field === 'createdAt' ) {
1060- returnValue [ '_created_at' ] = returnValue [ field ] ;
1061- delete returnValue [ field ] ;
1062- } else if ( field === 'updatedAt' ) {
1063- returnValue [ '_updated_at' ] = returnValue [ field ] ;
1064- delete returnValue [ field ] ;
1060+ if ( ! rawFieldNames ) {
1061+ if ( field === 'objectId' ) {
1062+ returnValue [ '_id' ] = returnValue [ field ] ;
1063+ delete returnValue [ field ] ;
1064+ } else if ( field === 'createdAt' ) {
1065+ returnValue [ '_created_at' ] = returnValue [ field ] ;
1066+ delete returnValue [ field ] ;
1067+ } else if ( field === 'updatedAt' ) {
1068+ returnValue [ '_updated_at' ] = returnValue [ field ] ;
1069+ delete returnValue [ field ] ;
1070+ }
10651071 }
10661072 }
10671073 return returnValue ;
@@ -1073,24 +1079,26 @@ export class MongoStorageAdapter implements StorageAdapter {
10731079 // two functions and making the code even harder to understand, I decided to split it up. The
10741080 // difference with this function is we are not transforming the values, only the keys of the
10751081 // pipeline.
1076- _parseAggregateProjectArgs ( schema : any , pipeline : any ) : any {
1082+ _parseAggregateProjectArgs ( schema : any , pipeline : any , rawValues ? : boolean , rawFieldNames ? : boolean ) : any {
10771083 const returnValue = { } ;
10781084 for ( const field in pipeline ) {
1079- if ( schema . fields [ field ] && schema . fields [ field ] . type === 'Pointer' ) {
1085+ if ( ! rawFieldNames && schema . fields [ field ] && schema . fields [ field ] . type === 'Pointer' ) {
10801086 returnValue [ `_p_${ field } ` ] = pipeline [ field ] ;
10811087 } else {
1082- returnValue [ field ] = this . _parseAggregateArgs ( schema , pipeline [ field ] ) ;
1088+ returnValue [ field ] = this . _parseAggregateArgs ( schema , pipeline [ field ] , rawValues , rawFieldNames ) ;
10831089 }
10841090
1085- if ( field === 'objectId' ) {
1086- returnValue [ '_id' ] = returnValue [ field ] ;
1087- delete returnValue [ field ] ;
1088- } else if ( field === 'createdAt' ) {
1089- returnValue [ '_created_at' ] = returnValue [ field ] ;
1090- delete returnValue [ field ] ;
1091- } else if ( field === 'updatedAt' ) {
1092- returnValue [ '_updated_at' ] = returnValue [ field ] ;
1093- delete returnValue [ field ] ;
1091+ if ( ! rawFieldNames ) {
1092+ if ( field === 'objectId' ) {
1093+ returnValue [ '_id' ] = returnValue [ field ] ;
1094+ delete returnValue [ field ] ;
1095+ } else if ( field === 'createdAt' ) {
1096+ returnValue [ '_created_at' ] = returnValue [ field ] ;
1097+ delete returnValue [ field ] ;
1098+ } else if ( field === 'updatedAt' ) {
1099+ returnValue [ '_updated_at' ] = returnValue [ field ] ;
1100+ delete returnValue [ field ] ;
1101+ }
10941102 }
10951103 }
10961104 return returnValue ;
@@ -1101,16 +1109,16 @@ export class MongoStorageAdapter implements StorageAdapter {
11011109 // The <expression> could be a column name, prefixed with the '$' character. We'll look for
11021110 // these <expression> and check to see if it is a 'Pointer' or if it's one of createdAt,
11031111 // updatedAt or objectId and change it accordingly.
1104- _parseAggregateGroupArgs ( schema : any , pipeline : any ) : any {
1112+ _parseAggregateGroupArgs ( schema : any , pipeline : any , rawFieldNames ? : boolean ) : any {
11051113 if ( Array . isArray ( pipeline ) ) {
1106- return pipeline . map ( value => this . _parseAggregateGroupArgs ( schema , value ) ) ;
1114+ return pipeline . map ( value => this . _parseAggregateGroupArgs ( schema , value , rawFieldNames ) ) ;
11071115 } else if ( typeof pipeline === 'object' ) {
11081116 const returnValue = { } ;
11091117 for ( const field in pipeline ) {
1110- returnValue [ field ] = this . _parseAggregateGroupArgs ( schema , pipeline [ field ] ) ;
1118+ returnValue [ field ] = this . _parseAggregateGroupArgs ( schema , pipeline [ field ] , rawFieldNames ) ;
11111119 }
11121120 return returnValue ;
1113- } else if ( typeof pipeline === 'string' ) {
1121+ } else if ( typeof pipeline === 'string' && ! rawFieldNames ) {
11141122 const field = pipeline . substring ( 1 ) ;
11151123 if ( schema . fields [ field ] && schema . fields [ field ] . type === 'Pointer' ) {
11161124 return `$_p_$ { field } `;
0 commit comments