Last active
May 1, 2019 11:17
-
-
Save alistairjevans/2fc30366be03015d24a0f719731c3741 to your computer and use it in GitHub Desktop.
LockModel with a TTL Index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LockModel | |
{ | |
public string Id { get; set; } | |
/// <summary> | |
/// I'm going to set this to the moment in time when the lock should be cleared. | |
/// </summary> | |
public DateTime ExpireAt { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In our LockProvider constructor... | |
// Specify a TTL index on the ExpiryPoint field. | |
collection.Indexes.CreateOne(new CreateIndexModel<LockModel>( | |
Builders<LockModel>.IndexKeys.Ascending(l => l.ExpireAt), | |
new CreateIndexOptions | |
{ | |
ExpireAfter = TimeSpan.Zero | |
} | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment