Last active
November 26, 2024 02:33
-
-
Save travist/5133ade419362685bb81d29034be4c2d to your computer and use it in GitHub Desktop.
Mongo Delete multiple projects and resources within it.
This file contains hidden or 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
db.projects.find({_id: {$in: [ | |
ObjectId('63ebe4e2902342342db152a8'), | |
ObjectId('642324234234a13675034017'), | |
ObjectId('642c68506234234234241869'), | |
]}}).forEach(function(project) { | |
print('Deleting project ' + project.name); | |
db.forms.find({project: project._id}).forEach(function(form) { | |
print('Deleting revisions for ' + form.title); | |
db.formrevisions.deleteMany({form: form._id, project: project._id}); | |
print('Deleting submissions for ' + form.title); | |
var count = 0; | |
db.submissions.find({form: form._id, project: project._id}).forEach(function(submission) { | |
count++; | |
if (count % 100 === 0) { | |
print('Deleted ' + count + ' submissions'); | |
} | |
db.submissions.deleteOne({_id: submission._id}); | |
}); | |
print('Deleting actions for ' + form.title); | |
db.actions.deleteMany({form: form._id, project: project._id}); | |
print('Deleting form ' + form.title); | |
db.forms.deleteOne({_id: form._id}); | |
}); | |
print('Deleting roles'); | |
db.roles.deleteMany({project: project._id}); | |
print('Deleting project ' + project.name); | |
db.projects.deleteOne({_id: project._id}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment