Skip to content

Commit abd4c7f

Browse files
authored
Merge pull request #7059 from Countly/anna/master
[core] fixes for changeOwner script
2 parents 16de64c + c4e167d commit abd4c7f

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

bin/scripts/modify-data/changeOwner.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ pluginManager.dbConnection("countly").then((db) => {
2020

2121
function changeOwner(NEW_ID, OLD_ID, done) {
2222
changeOwnerDashboard(NEW_ID, OLD_ID, function() {
23-
common.db.collection("alerts").update({createdBy: OLD_OID}, {$set: {createdBy: NEW_OID}}, function(err, res) {
23+
common.db.collection("alerts").updateMany({createdBy: OLD_OID}, {$set: {createdBy: NEW_OID}}, function(err, res) {
2424
console.log("alerts", err, res && res.result);
25-
common.db.collection("auth_tokens").update({owner: OLD_ID}, {$set: {owner: NEW_ID}}, function(err, res) {
25+
common.db.collection("auth_tokens").updateMany({owner: OLD_ID}, {$set: {owner: NEW_ID}}, function(err, res) {
2626
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) {
27+
common.db.collection("calculated_metrics").updateMany({owner_id: OLD_ID}, {$set: {owner_id: NEW_ID}}, function(err, res) {
2828
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) {
29+
common.db.collection("concurrent_users_alerts").updateMany({created_by: OLD_OID}, {$set: {created_by: NEW_OID}}, function(err, res) {
3030
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) {
31+
common.db.collection("data_migrations").updateMany({userid: OLD_OID}, {$set: {userid: NEW_OID}}, function(err, res) {
3232
console.log("data_migrations", err, res && res.result);
3333
changeOwnerLongTasks(NEW_ID, OLD_ID, function(err, res) {
3434
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) {
35+
common.db.collection("messages").updateMany({"info.createdBy": OLD_ID}, {$set: {"info.createdBy": NEW_ID}}, function(err, res) {
3636
console.log("messages", err, res && res.result);
37-
common.db.collection("notes").update({owner: OLD_ID}, {$set: {owner: NEW_ID}}, function(err, res) {
37+
common.db.collection("notes").updateMany({owner: OLD_ID}, {$set: {owner: NEW_ID}}, function(err, res) {
3838
console.log("notes", err, res && res.result);
39-
common.db.collection("reports").update({user: OLD_OID}, {$set: {user: NEW_OID}}, function(err, res) {
39+
common.db.collection("reports").updateMany({user: OLD_OID}, {$set: {user: NEW_OID}}, function(err, res) {
4040
console.log("reports", err, res && res.result);
4141
done();
4242
});
@@ -81,12 +81,15 @@ pluginManager.dbConnection("countly").then((db) => {
8181
}
8282
};
8383

84-
common.db.collection("dashboards").update({_id: dash._id}, update, function(err) {
84+
common.db.collection("dashboards").update({_id: dash._id}, update, function(err, res) {
8585
if (err) {
8686
console.log("Error while updating dashboard ", JSON.stringify(dash));
8787
console.log("Error message ", err.message);
8888
return done(true);
8989
}
90+
else {
91+
console.log(" " + dash._id + " " + JSON.stringify((res && res.result) || {}));
92+
}
9093

9194
return done(null);
9295
});
@@ -136,7 +139,7 @@ pluginManager.dbConnection("countly").then((db) => {
136139
});
137140
});
138141
}).then(function() {
139-
console.log(cn + " records updated");
142+
console.log(cn + " records updated for long_tasks");
140143
done();
141144
});
142145
}

0 commit comments

Comments
 (0)