我正在努力使用天蓝色的功能。该功能的目的是从cosmos db中获取一些对象,对其进行更新,然后将其保存回去。
该函数看起来大致如此
[FunctionName("update-in-cosmosdb")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req,
[CosmosDB(
databaseName: "name",
collectionName: "col-name",
ConnectionStringSetting = "COSMOSDB-CONNECTIONSTRING")] DocumentClient client,
ILogger log)
{
var documentDatabase = Environment.GetEnvironmentVariable("DB-NAME");
var documentCollection = Environment.GetEnvironmentVariable("COL-NAME");
var uri = UriFactory.CreateDocumentCollectionUri(documentDatabase, documentCollection);
var query = client.CreateDocumentQuery<MyModelClass>(uri,
"SELECT TOP 10 c.id, c.PropertyToChange FROM c WHERE c.id IN (" + ids+ ")", new FeedOptions {EnableCrossPartitionQuery = true}).ToList();
foreach (var o in query)
{
o.PropertyToChange = someNewValue;
}
然后我想将更新的相应文档保存在cosmos-db中。应该怎么做呢?可能重要的事实是,MyModelClass仅包含一些属性-cosmos-db中的文档要复杂得多,我不想触及其他属性。 MyModelClass当然包含ID