且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何为Cosmos db中的每个文档设置字段?

更新时间:2023-02-14 11:32:44

假设一次数据维护任务,可以说最简单的解决方案是创建一个单一用途的.NET Core控制台应用程序,并使用SDK查询项目.需要更改并执行更新.例如,我已经使用这种方法来重命名属性.这适用于任何Cosmos数据库,不需要部署任何存储的proc或其他方式.

Assuming a one-time data maintenance task, arguably the simplest solution is to create a single purpose .NET Core console app and use the SDK to query for the items that require changes, and perform the updates. I've used this approach to rename properties, for example. This works for any Cosmos database and doesn't require deploying any stored procs or otherwise.

理想情况下,它被设计为幂等的,因此如果需要多次通过才能捕获新数据,则可以多次运行.如果项数很大,则可以选择使用SDK操作来扩大启动时的吞吐量并在完成后缩小.为了提高性能,请使其靠近Azure虚拟机或功能上的终结点.

Ideally, it is designed to be idempotent so it can be run multiple times if several passes are required to catch new data coming in. If the item count is large, one could optionally use the SDK operations to scale up throughput on start and scale back down when finished. For performance run it close to the endpoint on an Azure Virtual Machine or Function.