在 MongoDB 內使用 TTL
TTL == Time To Live
用於存放暫存資料var collection = _database.GetCollection<Student>("Students");
舊的實作方法(已過時)
1 | var index = collection.Indexes.CreateOne(Builders<Student>.IndexKeys.Ascending("expireAt"), |
新的實作方法
1 | var options = new CreateIndexOptions { ExpireAfter = new TimeSpan(0, 0, 20) }; |