fix db team leaders

pull/6686/head
Thibault Duplessis 2020-05-22 11:21:24 -06:00
parent 90b4fe2e7a
commit 01e5268602
1 changed files with 8 additions and 3 deletions

View File

@ -1,4 +1,9 @@
db.team.find({},{createdBy:1}).forEach(t => {
db.team.update({_id:t._id},{$set:{leaders:[t.createdBy]}});
db.team.find().forEach(t => {
if (t.leaders.length == 1 && t.leaders[0] == t.createdBy) return;
const leaders = db.team_member.distinct('user',{team:t._id,user:{$in:t.leaders}});
if (leaders.length != t.leaders.length) {
if (!leaders.length) leaders.push(t.createdBy);
print(`${t._id} ${t.name} ${t.leaders.join(',')} -> ${leaders.join(',')}`);
db.team.update({_id:t._id},{$set:{leaders:leaders}});
}
});
db.team.ensureIndex({leaders:1},{background:1})