MongoDb 2.0.7。 这就是在c#:
中为存储对象MyObject声明日期的方式public class MyObject
{
[BsonDateTimeOptions(Kind = DateTimeKind.Local)]
public DateTime Created { get; set; }
...
}
这就是索引的创建方式:
Collection.EnsureIndex(new IndexKeysBuilder<MyObject>().Ascending(l => l.Created), IndexOptions.SetName("CreatedDateIndex").SetTimeToLive(new TimeSpan(0, 0, 60)));
MongoVUE
工具确认使用CreatedDateIndex
为集合MyObject
创建了名为expireAfterSeconds = 60
的索引。没有为Created
字段声明的索引。
然而,集合中的项目永远不会被自动删除,我可以看到像这样的文档仍然有几天的旧项目:
{
"_id" : new BinData(3, "OVdRaIodPUKz7cCuaxnFpA=="),
"Created" : ISODate("2014-01-09T23:41:08.732Z"),
}
可能有什么问题?我只能猜测数据类型有问题,可能不是Bson Date类型,它甚至不会警告我,无论如何我甚至不知道如何验证它。
答案 0 :(得分:4)
TTL索引从2.2开始是新的,而你使用的是2.0.7 ......