Logs are automatically deleted when their size reaches a specific threshold.

In emergencies, you can run the compact command to delete oplogs. For more information, see Defragment the disk space to improve disk usage.
Note
  • You can only run this command on replica set instances.
  • Before running compact, you must log on to the local database where the oplog.rs collection is stored.