Last active
January 30, 2023 15:42
-
-
Save travist/3743b7e101003e75043b135eaa913ece to your computer and use it in GitHub Desktop.
Change team/project ownership to user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var EMAIL = ''; | |
var PROJECTID = ''; | |
db.projects.find({name: 'formio'}).forEach(function(project) { | |
db.forms.find({name: 'user', project: project._id}).forEach(function(userForm) { | |
print("User Form: " + userForm._id); | |
db.submissions.find({'data.email': EMAIL, form: userForm._id}).forEach(function(user) { | |
if (user) { | |
print("User: " + user._id); | |
db.projects.find({_id: ObjectId(PROJECTID)}).forEach(function(changeProject) { | |
if (changeProject) { | |
print("Changing project " + PROJECTID + " owner to " + user._id); | |
db.projects.updateOne({_id:changeProject._id}, {$set: {owner: user._id}}); | |
} | |
}); | |
} | |
else { | |
print("User not found"); | |
} | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var USERNAME = ''; | |
var TEAMS = []; | |
db.projects.find({name: 'formio'}).forEach(function(project) { | |
db.forms.find({name: 'user', project: project._id}).forEach(function(userForm) { | |
print("User Form: " + userForm._id); | |
db.submissions.find({'data.name': USERNAME, form: userForm._id}).forEach(function(user) { | |
if (user) { | |
print("User: " + user._id); | |
TEAMS.forEach(function(teamId) { | |
print("Updating team " + teamId + " to owner " + user._id); | |
db.submissions.updateOne({_id: ObjectId(teamId)}, {$set: {owner: user._id}}); | |
}); | |
} | |
else { | |
print("User not found"); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment