Last active
January 5, 2016 14:52
-
-
Save drpepper/210b0ec4d32334178254 to your computer and use it in GitHub Desktop.
IdeaWeave server scripts
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 cursor = db.challenges.find(); | |
while ( cursor.hasNext() ) { | |
var challenge = cursor.next(); | |
print("Examining challenge", challenge._id); | |
var newProjects = []; | |
for(var i = 0; i < challenge.projects.length; i++) { | |
if(db.projects.findOne({ _id: challenge.projects[i] })) { | |
print(" Including project", challenge.projects[i]); | |
newProjects.push(challenge.projects[i]); | |
} else { | |
print(" ** EXCLUDING project", challenge.projects[i]); | |
} | |
} | |
//print(" newProjects", newProjects) | |
db.challenges.update({ _id: challenge._id }, { $set: { projects: newProjects } }); | |
} |
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 cursor = db.credits.find(); | |
var creditsToRemove = []; | |
while ( cursor.hasNext() ) { | |
var credit = cursor.next(); | |
print("Examining credit", credit._id); | |
if(db.badges.findOne({ _id: credit.badge })) { | |
print(" Badge exists"); | |
} else { | |
print(" ** Badge does not exist"); | |
creditsToRemove.push(credit._id); | |
} | |
} | |
print("Removing credits", creditsToRemove); | |
for(var i = 0; i < creditsToRemove.length; i++) { | |
db.credits.remove({ _id: creditsToRemove[i] }, { justOne: true }); | |
} |
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 cursor = db.tags.find(); | |
while ( cursor.hasNext() ) { | |
var tag = cursor.next(); | |
tag.userCount = db.users.count({ tags: { $in: [tag._id] } }); | |
tag.projectCount = db.projects.count({ tags: { $in: [tag._id] } }); | |
tag.challengeCount = db.challenges.count({ tags: { $in: [tag._id] } }); | |
tag.ideaCount = db.ideas.count({ tags: { $in: [tag._id] } }); | |
tag.entityCount = tag.userCount + tag.projectCount + tag.challengeCount + tag.ideaCount; | |
// Remove old count field | |
delete tag.number; | |
print("Updating tag", tag.title, "counts to", tag.userCount, tag.projectCount, tag.challengeCount, tag.ideaCount, tag.entityCount); | |
db.tags.save(tag); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment