I create a collection of objects
public class User
{
public User(string fullname, string email)
{
Fullname = fullname;
Email = email;
}public string Fullname { get; } public string Email { get; } }
And create the index and some docs
var collection = _database.GetCollection(“bar”);
collection.Indexes.CreateOne(new CreateIndexModel
(new BsonDocument(“lastModifiedDate”, 1), new CreateIndexOptions { ExpireAfter = new TimeSpan(0, 0, 30) }));var user = new User("Vasya", "billgates@ms.com"); collection.InsertOne(user.ToBsonDocument()); var user1 = new User("Petya", "Petya@ms.com"); collection.InsertOne(user1.ToBsonDocument()); var user2 = new User("Kolya", "Kolya@ms.com"); collection.InsertOne(user2.ToBsonDocument()); count = collection.CountDocuments(new BsonDocument());
But when I see http://localhost:8081/db/dbtest/ then I do not see any TTL and documents do not expire after 30 secs.
What I do wrong? How to create collection or documents in it with TTL?