0

I want the collection i am inserting into mongodb to expire after a certain amount of time.

var db = mongo.GetDatabase("weatherdb");
using (mongo.RequestStart(db))
{
    var collection = db.GetCollection<BsonDocument>("weatherdatanew24")
        .EnsureIndex("Date" -> 1, "expireAfterSeconds" -> 120);
}

but the ensureINdex part is not working i think. Help please.

4

1 回答 1

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);
}
于 2014-05-05T05:06:50.767 回答