2013-02-15 78 views
4

Mongo不會過期舊集合。我檢查了以確保我的索引是類型日期。如何讓mongo TTL在c#中過期

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") 
+0

您是否檢查過您是否意外地違反了其中一個約束條件(http://docs.mongodb.org/manual/tutorial/expire-data/)。只要''expiry''是一個日期時間字段並且該字段中沒有其他索引,就應該可以工作。 – 2013-02-15 01:59:03

+0

到期 – James 2013-02-15 02:23:42

+0

'ExpireDate'和'expiry'旁邊沒有任何索引字段?如果我瞭解您的代碼段,那些需要匹配。 – WiredPrairie 2013-02-15 02:31:14

回答

2

代碼缺失[BsonElement( 「期滿」)]的ExpireTime屬性的頂部。 感謝@WiredPrairie的提示。