C# Driver TTL at specific time

Hi @Daniel_Svensson,

What happens in the Compass client is that the inserted document is removed way before 120 seconds. Could someone please share some light or put me in the right direction on how to achieve so I can have the behaviour that a document is removed 120 seconds after its actual ServiceDate? Or have I misunderstood TTL altogether?

When you set the expireAfterSeconds value to 0 (via ExpireAt) the TTL Index will remove documents at the_exact time_ specified by the indexed value.

var entity = new MyEntity()
{
  ServiceDate = servicedate,
  TestProp = testprop,
  CreatedAt = createdAt,
  ExpireAt = serviceDate.AddSeconds(120)
};

Given the example above, if ExpireAt is a date/time in the past, and adding 120 seconds to that timestamp would still be in the past, when the TTL background thread runs (every 60 seconds by default) ALL documents that match this criteria will be deleted.

I would start by reviewing the date/time of ExpireAt for these documents and comparing them to the current date/time to ensure the values are actually in the future; not in the past.