66 */
77
88
9- const { ObjectId } = require ( 'mongodb' ) ;
109const pluginManager = require ( '../../../plugins/pluginManager.js' ) ;
1110const common = require ( '../../../api/utils/common.js' ) ;
1211const drillCommon = require ( '../../../plugins/drill/api/common.js' ) ;
@@ -25,7 +24,7 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
2524
2625 //GET APP
2726 try {
28- const app = await countlyDb . collection ( "apps" ) . findOne ( { _id : ObjectId ( APP_ID ) } , { _id : 1 , name : 1 } ) ;
27+ const app = await countlyDb . collection ( "apps" ) . findOne ( { _id : countlyDb . ObjectID ( APP_ID ) } , { _id : 1 , name : 1 } ) ;
2928 console . log ( "App:" , app . name ) ;
3029 //GET EVENTS
3130 var events = [ ] ;
@@ -51,6 +50,27 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
5150 }
5251 ] ) . toArray ( ) ;
5352 events = events . length ? events [ 0 ] . list : [ ] ;
53+ const metaEvents = await drillDb . collection ( "drill_meta" ) . aggregate ( [
54+ {
55+ $match : {
56+ 'app_id' : app . _id + "" ,
57+ "type" : "e" ,
58+ "e" : { $regex : regex , $options : CASE_INSENSITIVE ? "i" : "" , $nin : events }
59+ }
60+ } ,
61+ {
62+ $group : {
63+ _id : "$e"
64+ }
65+ } ,
66+ {
67+ $project : {
68+ _id : 0 ,
69+ e : "$_id"
70+ }
71+ }
72+ ] ) . toArray ( ) ;
73+ events = events . concat ( metaEvents . map ( e => e . e ) ) ;
5474 }
5575 catch ( err ) {
5676 close ( "Invalid regex" ) ;
@@ -86,6 +106,7 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
86106 close ( err ) ;
87107 }
88108
109+
89110 async function deleteDrillEvents ( appId , events ) {
90111 for ( let i = 0 ; i < events . length ; i ++ ) {
91112 var collectionName = drillCommon . getCollectionName ( events [ i ] , appId ) ;
0 commit comments