4

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")
4

1 回答 1

2

代码在 ExpireTime 属性顶部缺少 [BsonElement("expiry")]。感谢@WiredPrairie 的提示。

于 2013-02-15T03:32:28.367 回答