Update move-deleted-classroom-members script

This commit is contained in:
Scott Erickson 2016-04-29 09:39:16 -07:00
parent 5884a7ce8d
commit 7415e61763

View file

@ -1,16 +1,17 @@
var classrooms = db.classrooms.find();
classrooms.forEach(function (classroom) {
printjson(classroom.members);
classroom.members.forEach(function (userID) {
var user = db.users.findOne({ _id: userID }, { deleted: true });
if (user.deleted) {
db.classrooms.update(
{ _id: classroom._id },
{
$addToSet: { deletedMembers: userID },
$pull: { members: userID },
},
);
}
});
print('classroom', classroom._id);
classroom.members.forEach(function (userID) {
var user = db.users.findOne({ _id: userID }, { deleted: true });
if (user.deleted) {
print('\tFOUND ONE', userID);
print('\t', db.classrooms.update(
{ _id: classroom._id },
{
$addToSet: { deletedMembers: userID },
$pull: { members: userID }
}
));
}
});
});