Skip to content

Instantly share code, notes, and snippets.

@drpepper
Last active January 5, 2016 14:52
Show Gist options
  • Save drpepper/210b0ec4d32334178254 to your computer and use it in GitHub Desktop.
Save drpepper/210b0ec4d32334178254 to your computer and use it in GitHub Desktop.
IdeaWeave server scripts
var cursor = db.tags.find();
while ( cursor.hasNext() ) {
var tag = cursor.next();
tag.title = tag.title.trim().toLowerCase();
db.tags.save(tag);
print("Updated", tag.title);
}
var cursor = db.tags.find();
var validTags = [];
while ( cursor.hasNext() ) {
var tag = cursor.next();
var name = tag.title.trim().toLowerCase();
if(validTags.indexOf(name) >= 0) {
print("Removing", name);
db.tags.remove({ _id: tag._id });
} else {
print("Skipping", name);
validTags.push(name);
}
}
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