Created
June 11, 2012 17:35
-
-
Save afeld/2911480 to your computer and use it in GitHub Desktop.
Jux: remove duplicate custom_links
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
db.users.find({'custom_links.1': {$exists: true}}).snapshot().forEach(function(user){ | |
var urls = {}, | |
keepLinks = []; | |
user.custom_links.forEach(function(link){ | |
var url = link.value.toString().toLowerCase().replace(/\/$/, '').replace(/^(https?:?\/\/)?(www\. ?)?/, ''); | |
if (!urls[url]){ | |
keepLinks.push(link); | |
urls[url] = true; | |
} | |
}); | |
if (user.custom_links.length !== keepLinks.length){ | |
print(user.username + '--------------------------------------'); | |
printjson(urls); | |
db.users.update({_id: user._id}, {$set: {custom_links: keepLinks}}, false, false); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment