@@ -15,28 +15,30 @@ const Promise = require('bluebird');
1515
1616pluginManager . dbConnection ( "countly" ) . then ( ( db ) => {
1717 common . db = db ;
18+ const NEW_ID_STR = NEW_ID ;
19+ const OLD_ID_STR = OLD_ID ;
1820 const NEW_OID = common . db . ObjectID ( NEW_ID ) ;
1921 const OLD_OID = common . db . ObjectID ( OLD_ID ) ;
2022
2123 function changeOwner ( NEW_ID , OLD_ID , done ) {
22- changeOwnerDashboard ( NEW_ID , OLD_ID , function ( ) {
23- common . db . collection ( "alerts" ) . update ( { createdBy : OLD_OID } , { $set : { createdBy : NEW_OID } } , function ( err , res ) {
24+ changeOwnerDashboard ( NEW_ID_STR , OLD_ID_STR , function ( ) {
25+ common . db . collection ( "alerts" ) . updateMany ( { createdBy : OLD_OID } , { $set : { createdBy : NEW_OID } } , function ( err , res ) {
2426 console . log ( "alerts" , err , res && res . result ) ;
25- common . db . collection ( "auth_tokens" ) . update ( { owner : OLD_ID } , { $set : { owner : NEW_ID } } , function ( err , res ) {
27+ common . db . collection ( "auth_tokens" ) . updateMany ( { owner : OLD_ID_STR } , { $set : { owner : NEW_ID_STR } } , function ( err , res ) {
2628 console . log ( "auth_tokens" , err , res && res . result ) ;
27- common . db . collection ( "calculated_metrics" ) . update ( { owner_id : OLD_ID } , { $set : { owner_id : NEW_ID } } , function ( err , res ) {
29+ common . db . collection ( "calculated_metrics" ) . updateMany ( { owner_id : OLD_ID_STR } , { $set : { owner_id : NEW_ID_STR } } , function ( err , res ) {
2830 console . log ( "calculated_metrics" , err , res && res . result ) ;
29- common . db . collection ( "concurrent_users_alerts" ) . update ( { created_by : OLD_OID } , { $set : { created_by : NEW_OID } } , function ( err , res ) {
31+ common . db . collection ( "concurrent_users_alerts" ) . updateMany ( { created_by : OLD_OID } , { $set : { created_by : NEW_OID } } , function ( err , res ) {
3032 console . log ( "concurrent_users_alerts" , err , res && res . result ) ;
31- common . db . collection ( "data_migrations" ) . update ( { userid : OLD_OID } , { $set : { userid : NEW_OID } } , function ( err , res ) {
33+ common . db . collection ( "data_migrations" ) . updateMany ( { userid : OLD_OID } , { $set : { userid : NEW_OID } } , function ( err , res ) {
3234 console . log ( "data_migrations" , err , res && res . result ) ;
33- changeOwnerLongTasks ( NEW_ID , OLD_ID , function ( err , res ) {
35+ changeOwnerLongTasks ( NEW_ID_STR , OLD_ID_STR , function ( err , res ) {
3436 console . log ( "messages" , err , res && res . result ) ; // "createdBy": { "$oid": "63442fa1ec94a1edb60f2453"}
35- common . db . collection ( "messages" ) . update ( { "info.createdBy" : OLD_ID } , { $set : { "info.createdBy" : NEW_ID } } , function ( err , res ) {
37+ common . db . collection ( "messages" ) . updateMany ( { "info.createdBy" : OLD_ID } , { $set : { "info.createdBy" : NEW_ID } } , function ( err , res ) {
3638 console . log ( "messages" , err , res && res . result ) ;
37- common . db . collection ( "notes" ) . update ( { owner : OLD_ID } , { $set : { owner : NEW_ID } } , function ( err , res ) {
39+ common . db . collection ( "notes" ) . updateMany ( { owner : OLD_ID_STR } , { $set : { owner : NEW_ID_STR } } , function ( err , res ) {
3840 console . log ( "notes" , err , res && res . result ) ;
39- common . db . collection ( "reports" ) . update ( { user : OLD_OID } , { $set : { user : NEW_OID } } , function ( err , res ) {
41+ common . db . collection ( "reports" ) . updateMany ( { user : OLD_OID } , { $set : { user : NEW_OID } } , function ( err , res ) {
4042 console . log ( "reports" , err , res && res . result ) ;
4143 done ( ) ;
4244 } ) ;
@@ -81,12 +83,15 @@ pluginManager.dbConnection("countly").then((db) => {
8183 }
8284 } ;
8385
84- common . db . collection ( "dashboards" ) . update ( { _id : dash . _id } , update , function ( err ) {
86+ common . db . collection ( "dashboards" ) . update ( { _id : dash . _id } , update , function ( err , res ) {
8587 if ( err ) {
8688 console . log ( "Error while updating dashboard " , JSON . stringify ( dash ) ) ;
8789 console . log ( "Error message " , err . message ) ;
8890 return done ( true ) ;
8991 }
92+ else {
93+ console . log ( " " + dash . _id + " " + JSON . stringify ( ( res && res . result ) || { } ) ) ;
94+ }
9095
9196 return done ( null ) ;
9297 } ) ;
@@ -136,7 +141,7 @@ pluginManager.dbConnection("countly").then((db) => {
136141 } ) ;
137142 } ) ;
138143 } ) . then ( function ( ) {
139- console . log ( cn + " records updated" ) ;
144+ console . log ( cn + " records updated for long_tasks " ) ;
140145 done ( ) ;
141146 } ) ;
142147 }
0 commit comments