【发布时间】:2016-04-11 07:25:54
【问题描述】:
我想知道是否可以在嵌套文档上使用 TTL。
场景
我有Account,里面有Sessions。 Sessions 需要在 30 分钟后过期。我已经设置了所有内容,但显然当我在Account.Sessions.EndDateTime 上设置 TTL 索引时,它会删除整个Account。我可以确保它只删除Session吗?
这就是它在数据库中的样子。请注意,当EndDateTime 到来时,它将如何删除整个Account 而不仅仅是Session。
{
"_id" : ObjectId("53af273888dba003f429540b"),
"Email" : "steve@s3te5ve.com",
"PasswordHash" : "CZaBEQRbwWNgJBjyhks7gH0Z3v5ZvDkW29pryF0DEXyE8rIw0NA4x39+uQneArKaUv97sP1e+e22YT1glbqQsw==",
"PasswordSalt" : "100000.Qx4D8uj7oDcWHRTLGRRTDwVkw2UcaM52XkDR9k2ga073Ow==",
"Sessions" : [
{
"Token" : "da55cf0783c4249b26283948fcae6caa15df320ca456203045aea81cad691df8",
"IpAddress" : "::1",
"StartDateTime" : ISODate("2014-06-28T20:36:27.000Z"),
"EndDateTime" : ISODate("2014-06-28T21:06:27.000Z")
}
]
}
这是我创建上述索引的地方。
if (!_db.Accounts.IndexExists("Sessions.EndDateTime"))
{
_db.Accounts.CreateIndex(IndexKeys.Ascending("Sessions.EndDateTime"),
IndexOptions.SetTimeToLive(new TimeSpan(0)));
}
【问题讨论】:
-
+1 好问题,我认为答案是否定的。
标签: c# mongodb indexing mongodb-.net-driver ttl