@@ -9,10 +9,10 @@ const { wildCardForAllBuckets } = require('../constants');
99class PipelineFactory {
1010 /**
1111 * @constructor
12- * @param {number } locationStrippingThreshold threshold for stripping location data
12+ * @param {number } locationStrippingBytesThreshold threshold for stripping location data
1313 */
14- constructor ( locationStrippingThreshold ) {
15- this . _locationStrippingThreshold = locationStrippingThreshold ;
14+ constructor ( locationStrippingBytesThreshold ) {
15+ this . _locationStrippingBytesThreshold = locationStrippingBytesThreshold ;
1616 }
1717
1818 /**
@@ -71,31 +71,35 @@ class PipelineFactory {
7171 const pipeline = [
7272 stage ,
7373 ] ;
74- if ( this . _locationStrippingThreshold >= 0 ) {
74+ if ( this . _locationStrippingBytesThreshold > 0 ) {
7575 pipeline . push ( {
7676 $set : {
77- 'fullDocument.value.location' :
78- this . _locationStrippingExpression ( 'fullDocument.value.location' ) ,
79- 'updateDescription.updatedFields.value.location' :
80- this . _locationStrippingExpression ( 'updateDescription.updatedFields.value.location' ) ,
77+ 'fullDocument.value.location' : {
78+ $cond : {
79+ if : { $gte : [
80+ '$fullDocument.value.content-length' ,
81+ this . _locationStrippingBytesThreshold ,
82+ ] } ,
83+ then : '$$REMOVE' ,
84+ else : '$fullDocument.value.location' ,
85+ } ,
86+ } ,
87+ 'updateDescription.updatedFields.value.location' : {
88+ $cond : {
89+ if : { $gte : [
90+ '$updateDescription.updatedFields.value.content-length' ,
91+ this . _locationStrippingBytesThreshold ,
92+ ] } ,
93+ then : '$$REMOVE' ,
94+ else : '$updateDescription.updatedFields.value.location' ,
95+ } ,
96+ } ,
8197 }
8298 } ) ;
8399 }
84100 return JSON . stringify ( pipeline ) ;
85101 }
86102
87- _locationStrippingExpression ( field ) {
88- return {
89- $switch : {
90- branches : [
91- { case : { $not : [ { $isArray : `$${ field } ` } ] } , then : '$$REMOVE' } ,
92- { case : { $gte : [ { $size : `$${ field } ` } , this . _locationStrippingThreshold ] } , then : '$$REMOVE' } ,
93- ] ,
94- default : `$${ field } ` ,
95- }
96- } ;
97- }
98-
99103 /**
100104 * Makes connector pipeline stage, to then be used by getPipeline.
101105 * @param {string[] | undefined } buckets buckets assigned to this connector
0 commit comments