Last active
December 15, 2015 16:59
-
-
Save imtapps/5292838 to your computer and use it in GitHub Desktop.
MongoDB update queries
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
//rename collection from fs to attachments | |
db.fs.files.renameCollection('attachments.files') | |
db.fs.chunks.renameCollection('attachments.chunks') | |
//move the tags 'AppendToApplication' and 'AgentDownload' to meta_tags | |
db.attachments.files.find({tags: {$exists: true}, meta_tags: {$exists: true}}).forEach(function (e) { | |
var meta_tags = []; | |
if(e.tags.forEach){ | |
e.tags.forEach(function (mt) { | |
meta_tags.push(mt); | |
}); | |
} else { | |
meta_tags.push(e.tags); | |
} | |
meta_tags.push('company_level'); | |
e.meta_tags = meta_tags; | |
delete e.tags; | |
db.attachments.files.save(e); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment