I have a challenge where I need to delete 50% of the records from my MongoDB collection, specifically targeting the oldest ones.
Here's the script I currently have:
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});
});
Since I'm using 'each' to iterate through and delete each record individually, I'm wondering if there is a way to delete all records at once with a single MongoDB instruction. Unfortunately, I haven't been able to find this information on Google. Is there a way to achieve this in MongoDB?