如何从asp.net中使用mongodb的TTL属性
我希望插入mongodb的集合在一定时间后过期如何从asp.net中使用mongodb的TTL属性,asp.net,mongodb,ttl,Asp.net,Mongodb,Ttl,我希望插入mongodb的集合在一定时间后过期 var db = mongo.GetDatabase("weatherdb"); using (mongo.RequestStart(db)) { var collection = db.GetCollection<BsonDocument>("weatherdatanew24") .EnsureIndex("Date" -> 1, "expireAfterSeconds" -> 120); } v
var db = mongo.GetDatabase("weatherdb");
using (mongo.RequestStart(db))
{
var collection = db.GetCollection<BsonDocument>("weatherdatanew24")
.EnsureIndex("Date" -> 1, "expireAfterSeconds" -> 120);
}
var db=mongo.GetDatabase(“weatherdb”);
使用(mongo.RequestStart(db))
{
var collection=db.GetCollection(“weatherdatanew24”)
.EnsureIndex(“日期”->1,“秒后到期”->120);
}
但我认为ensureINdex部分不起作用。
请帮忙。试试这个:
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);
}
我这样做了,但它给出了一个错误,即不能将void赋值给隐式类型的局部变量