Skip to content

Instantly share code, notes, and snippets.

@thesmith
Created April 19, 2011 17:56
Show Gist options
  • Save thesmith/929029 to your computer and use it in GitHub Desktop.
Save thesmith/929029 to your computer and use it in GitHub Desktop.
Delete sub items from container
var lookup = 'http://pressassociation.com/brands/1166';
var i=0;
var container = db.content.findOne({lookup: lookup});
print('container currently has '+container.contents.length+' items.');
for (i=0; i<container.contents.length; i++) {
if (container.contents[i] != null && container.contents[i].specialization == 'film') {
print('removing episode at poisition '+i+': '+container.contents[i]._id+' - '+container.contents[i].title);
//eval('db.content.update({_id: container._id}, {$unset: {"contents.'+i+'": 1 }})');
}
}
db.content.update({_id: container._id}, {$pull : {"contents" : null }});
var container = db.content.findOne({lookup: lookup});
print('container now has '+container.contents.length+' items.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment