from pymongo import MongoClient # Configure MongoDB connection client = MongoClient('mongodb://localhost:27017/') db = client['twitter_database'] collection = db['tweets'] # Find the last tweet in the collection last_tweet = collection.find_one({}, sort=[('$natural', -1)]) # Print the last tweet print(last_tweet)