@@ -16,11 +16,13 @@ import { MongoDbPushConfig } from '../../Types';
1616import BaseConfig from '../configuration/abstractions/BaseConfig' ;
1717import GQLError from '../../errors/GQLError' ;
1818import userMessages from '../../errors/UserMessages' ;
19+ import BaseLogger from '../logging/abstractions/BaseLogger' ;
1920
2021@injectable ( )
2122export default class MongoDb extends BaseDatabase {
2223 @inject ( TYPES . Shell ) protected readonly shell ! : Shell ;
2324 @inject ( TYPES . BackendConfig ) private readonly config ! : BaseConfig ;
25+ @inject ( TYPES . BackendLogger ) private readonly logger ! : BaseLogger ;
2426
2527 private mongoConnections : Map < string , MongoClient > = new Map < string , MongoClient > ( ) ;
2628
@@ -97,6 +99,7 @@ export default class MongoDb extends BaseDatabase {
9799 pipeline : { [ k : string ] : any } [ ] ,
98100 limit ?: number ,
99101 ) : Promise < any [ ] > {
102+ //this.logger.info('Pipeline', pipeline).then();
100103 try {
101104 const collection = await this . getCollection ( entity ) ;
102105 const aggregation = collection . aggregate ( pipeline ) ;
@@ -214,6 +217,12 @@ export default class MongoDb extends BaseDatabase {
214217 } ;
215218 const getBrowser = ( ) =>
216219 MongoDb . getFilterObjectFromStringFilterOption ( queryOptions , 'browser' , 'browser_name' ) ;
220+ const getBrowserVersion = ( ) =>
221+ MongoDb . getFilterObjectFromStringFilterOption (
222+ queryOptions ,
223+ 'browser_version' ,
224+ 'browser_version' ,
225+ ) ;
217226 const getScreenSize = ( ) =>
218227 MongoDb . getFilterObjectFromStringFilterOption (
219228 queryOptions ,
@@ -257,6 +266,7 @@ export default class MongoDb extends BaseDatabase {
257266 getReferrerTld ( ) ,
258267 getMobile ( ) ,
259268 getBrowser ( ) ,
269+ getBrowserVersion ( ) ,
260270 getScreenSize ( ) ,
261271 getOS ( ) ,
262272 getCustomReleaseId ( ) ,
@@ -268,27 +278,47 @@ export default class MongoDb extends BaseDatabase {
268278 } , { } as { [ k : string ] : any } ) as { [ p : string ] : any } ;
269279 }
270280
271- public async simpleAppAggregation (
281+ protected async simpleAppAggregation < T extends string | string [ ] > (
272282 app : App ,
273283 queryOptions : AppQueryOptions ,
274- key : string ,
284+ key : T ,
275285 checkExists = false ,
276286 stringNulls = false ,
277287 ) : Promise < {
278- result : { key : string ; user_count : number ; event_count : number } [ ] ;
288+ result : {
289+ key : T extends string ? string : { field : string ; value : string } [ ] ;
290+ user_count : number ;
291+ event_count : number ;
292+ } [ ] ;
279293 from : Date ;
280294 to : Date ;
281295 } > {
282296 const getMatch = ( ) => {
283297 const match = this . getAppFilter ( queryOptions ) ;
284298 if ( checkExists ) {
285- match [ key ] = { $exists : true } ;
299+ if ( typeof key === 'string' ) {
300+ match [ key ] = { $exists : true } ;
301+ } else {
302+ key . forEach ( ( _ ) => ( match [ _ ] = { $exists : true } ) ) ;
303+ }
286304 }
287305 return match ;
288306 } ;
289307
290- const getKey = ( ) =>
291- stringNulls ? { $ifNull : [ '$' + key , MongoDb . NULL_AS_STRING ] } : '$' + key ;
308+ const getKey = ( ) => {
309+ const handleNulls = ( k : string ) =>
310+ stringNulls ? { $ifNull : [ '$' + k , MongoDb . NULL_AS_STRING ] } : '$' + k ;
311+ if ( typeof key === 'string' ) {
312+ return handleNulls ( key ) ;
313+ } else {
314+ return key . map ( ( _ ) => {
315+ return {
316+ field : _ ,
317+ value : handleNulls ( _ ) ,
318+ } ;
319+ } ) ;
320+ }
321+ } ;
292322
293323 const rows = await this . runAggregation (
294324 app ,
@@ -938,6 +968,27 @@ export default class MongoDb extends BaseDatabase {
938968 return this . simpleAppAggregation ( app , queryOptions , 'browser_name' ) ;
939969 }
940970
971+ public async browserVersions (
972+ app : App ,
973+ queryOptions : AppQueryOptions ,
974+ ) : Promise < {
975+ result : {
976+ key : { field : string ; value : string } [ ] ;
977+ user_count : number ;
978+ event_count : number ;
979+ } [ ] ;
980+ from : Date ;
981+ to : Date ;
982+ } > {
983+ return this . simpleAppAggregation (
984+ app ,
985+ queryOptions ,
986+ [ 'browser_name' , 'browser_version' ] ,
987+ false ,
988+ true ,
989+ ) ;
990+ }
991+
941992 public async screenSizes (
942993 app : App ,
943994 queryOptions : AppQueryOptions ,
@@ -946,7 +997,7 @@ export default class MongoDb extends BaseDatabase {
946997 from : Date ;
947998 to : Date ;
948999 } > {
949- return this . simpleAppAggregation ( app , queryOptions , 'screen_size' ) ;
1000+ return this . simpleAppAggregation ( app , queryOptions , 'screen_size' , false , true ) ;
9501001 }
9511002
9521003 public async operatingSystems (
0 commit comments