Skip to content

Instantly share code, notes, and snippets.

@imtapps
Last active December 15, 2015 16:59
Show Gist options
  • Save imtapps/5292838 to your computer and use it in GitHub Desktop.
Save imtapps/5292838 to your computer and use it in GitHub Desktop.
MongoDB update queries
//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