I want to delete the 50% records of a MongoDB collection and lets say the we want to delete the oldest ones.
So I have this script:
var count = Twitter_tweets.find().count();
var limit = Math.round(count *.5);
var tweets = Twitter_tweets.find().sort({$natural:1}).limit(limit);
_.each(tweets,function(tweet){
Twitter_tweets.delete({_id : tweet._id});
});
But I'm using a each, since I don't know how to delete all records in one instruction, and I can't find that information on Google, how can achieve that with MongoDB?
Aucun commentaire:
Enregistrer un commentaire