Skip to content

Instantly share code, notes, and snippets.

@tairov
Created July 12, 2013 12:55
Show Gist options
  • Save tairov/5984246 to your computer and use it in GitHub Desktop.
Save tairov/5984246 to your computer and use it in GitHub Desktop.
remove documents from mongo js, shell, perl, grep
perl -ne '/([0-9a-z]{24,24})/ and print $1, "\n"' 12_07.txt | xargs -L 1 -I{} mongo 127.0.0.1:2707/db --eval \
"var _pid = '{}';
print(_pid);
var pin = db.pin.find({_id: ObjectId(_pid)});
if (pin && pin[0]._id) {
print('pin found: ' + pin[0]._id);
var photo = db.photo.find({_id: pin[0].p});
if (photo && photo[0]._id) {
print('photo_id: ', photo[0]._id);
print('remove photo: ', db.photo.remove({_id: photo[0]._id}) );
}
pin[0].st = 3;
print('save pin: ', db.pin.save(pin[0]) );
}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment