-1
  • hi I have a 30g mongodb collection(the oldest record is from 2019-09-11 13:50:00.034Z) in mongo repliCa set and I want to create a ttl index on is. this process will take too long cAN DAMAGE ANYTHING? OR better to DELETE MANUALY SOME DATA before creating ttl index?
NoamiA
  • 521
  • 4
  • 19

1 Answers1

1

To delete some documents, those documents need to be found first. The finding part can be fast if you have suitable indexes or slow otherwise.

So, depending on the delete query and the index situation, either approach could potentially be superior.

D. SM
  • 13,584
  • 3
  • 12
  • 21
  • i already have index on this time key I just want to add TTL to this one,so better delete before or just add TTL? – NoamiA Aug 25 '20 at 17:17
  • I would add the new index first. – D. SM Aug 25 '20 at 17:24
  • ok thanks and mongo mark for deletion documents or delete directly? – NoamiA Aug 25 '20 at 18:26
  • The TTL worker will run every 60 seconds and delete any expired documents. If your first batch will have many gigabytes of documents to delete, you can expect that will have a noticeable impact on performance. I would delete them in smaller batches first. – Joe Aug 26 '20 at 02:39