azure-cosmosdb - 使用 Cosmos Db Mongo API 按文档进行 TTL

标签 azure-cosmosdb

在 Cosmos Db 中,我使用文档级别的生存时间 (TTL),并且 Cosmos 似乎没有过期文档。此功能在使用 MongoDB API 的 Cosmos Db 中是否有效?如果是的话,我错过了什么?

  • 我将 Cosmos Db 与 MongoDB API 结合使用。
  • 在我的收藏的每个文档中都设置了“ttl”字段。
  • 在 Azure 中,我的集合的生存时间设置为“打开(无默认值)”。
  • 我在没有模拟器的情况下执行此操作,因为模拟器默认使用 SQL API。在模拟器中,我看到设置了“_ts”,但在 Azure 中没有看到此字段。
  • 我可以通过将生存时间设置为“打开”来切换到集合级别过期,并且文档会按预期过期。当我这样做时,我的“ttl”字段将被忽略,并遵循我在 Azure 中为“秒”设置的值。我仍然在文档中看到我的“ttl”字段。

虽然我在文档中没有看到“_ts”字段,但一篇有关索引的文章提到它是保留属性。这让人认为它是在幕后设置的,并且不会在查询中返回。

https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb-indexing "_ts is a Cosmos DB-specific field and is not accessible from MongoDB clients. It is a reserved (system) property that contains the timestamp of the document's last modification."

更新: 我检查了 MongoDB 支持页面( https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb-feature-support ),它表明集合级别 TTL 可用,并且没有提及文档级别。

Azure Cosmos DB supports a relative time-to-live (TTL) based on the timestamp of the document. TTL can be enabled for MongoDB API collections through the Azure portal.

更新: 我的 Azure 门户预览功能现在显示如下: Cosmos DB Preview Features

最佳答案

我使用 MongoDb API 在 Cosmos Db 中获得了文档级别的生存时间。我必须向 Microsoft 支持人员寻求帮助才能使其正常工作。微软大数据团队的回应如下。

Before enabling Document level TTL feature , I would like to clarify following about Document TTL feature details here.

The TTL feature is controlled by TTL properties at two levels - Collection level and the Document level.

Right now per Document level TTL for MongoDB accounts are not available by default. However, we can enable this feature for specific customers and this feature is set at an account level.

TTL is at a document level but the feature is enabled at an account level which means for all collections under the account, if there is a document with a TTL set, it will take effect. For other collections, if the TTL value is not set for each document, it would not be affected.

You needs to have an index on the _ts field for this to work.

To summarize this : - This feature works at Cosmos DB account level. We need to enable Document TTL feature in Cosmos DB backend on our side.

关于azure-cosmosdb - 使用 Cosmos Db Mongo API 按文档进行 TTL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50494494/

相关文章:

python - "Get"来自 cosmosdb 的 id 文档(不知道 _rid)

.net - 如何在 .Net Core 控制台应用程序中配置代理

azure - 每次创建 CosmosDB 文档时运行 Azure 函数应用并更新第二个集合中的文档

c# - DocumentDB 查询中的运算符之间

azure - DocumentDB 客户端 1.14 终止正在运行的进程

c# - 带有 MongoDB API 的 CosmosDB

java - Spring 与 mongo-java-driver 使用 Azure Cosmos DB 作为 MongoDB

azure - 使用 SQL 的 Cosmos DB 查询数组值

c# - Azure函数: Unable to convert trigger to CosmosDBTrigger

python-2.7 - 如何使用 azure cosmos db 最大化数据库上传速率