我希望我插入mongodb的集合在一段时间后过期。
var db = mongo.GetDatabase("weatherdb");
using (mongo.RequestStart(db))
{
var collection = db.GetCollection<BsonDocument>("weatherdatanew24")
.EnsureIndex("Date" -> 1, "expireAfterSeconds" -> 120);
}
但是我认为ensureINdex部分不起作用。 请帮助。
答案 0 :(得分:0)
试试这个:
var db = mongo.GetDatabase("weatherdb");
using (mongo.RequestStart(db))
{
var keys = IndexKeys.Ascending("Date");
var options = IndexOptions.SetTimeToLive(TimeSpan.FromMinutes(2));
var collection = db.GetCollection("weatherdatanew24").EnsureIndex(keys, options);
}