如何让mongo TTL在c#中过期

Mongo没有过期的旧收藏品.我检查以确保我的索引是类型日期.

var keys = IndexKeys.Ascending("expiry");
var options = IndexOptions.SetTimeToLive(TimeSpan.FromMinutes(1));

collection.EnsureIndex(keys, options);
this.ExpireDate = new BsonDateTime(DateTime.UtcNow.AddMinutes(5));
var insertResult = collection.Insert(this);

任何提示都将很高兴.

[
    {
            "v" : 1,
            "key" : {
                    "_id" : 1
            },
            "ns" : "Showsv1.ShowInfo",
            "name" : "_id_"
    },
    {
            "v" : 1,
            "key" : {
                    "expiry" : 1
            },
            "ns" : "Showsv1.ShowInfo",
            "name" : "expiry_1",
            "expireAfterSeconds" : 60
    }

]

"expiry" : ISODate("2013-02-15T02:40:45.876Z")

最佳答案 在ExpireTime属性之上缺少[BsonElement(“expiry”)]的代码.

谢谢@WiredPrairie的提示.

点赞