add migration to add invited users to group.invites, @lefnire I tried with _.each(db.users.find()) but doesnt seem to work for db records so I ended up using db.users.find().forEach... which instead seems to work. My first migration to cleanup deleted tags used _.each so I rewrote it using native forEach, just wanted to let you know that it is updated now.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
_.each(db.users.find(), function(user){
|
||||
db.users.find().forEach(function(user){
|
||||
var tags = user.tags;
|
||||
|
||||
_.each(user.tasks, function(task){
|
||||
@@ -6,7 +6,7 @@ _.each(db.users.find(), function(user){
|
||||
_.each(tags, function(tag){
|
||||
if(key == tag.id) delete task.tags[key];
|
||||
});
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
var groups = {};
|
||||
|
||||
db.users.find().forEach(function(user){
|
||||
if(user.invitations){
|
||||
if(user.invitations.party){
|
||||
groups[user.invitations.party.id] = groups[user.invitations.party.id] || [];
|
||||
groups[user.invitations.party.id].push(user._id);
|
||||
}
|
||||
|
||||
if(user.invitations.guilds){
|
||||
_.each(user.invitations.guilds, function(guild){
|
||||
groups[guild.id] = groups[guild.id] || [];
|
||||
groups[guild.id].push(user._id);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
_.each(groups, function(usersInvited, groupId){
|
||||
var group = db.groups.findOne({_id: groupId});
|
||||
|
||||
if(group){
|
||||
group.invites = usersInvited;
|
||||
|
||||
try {
|
||||
db.groups.update({_id: groupId}, group);
|
||||
} catch(e) {
|
||||
print(e);
|
||||
}
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user