【问题标题】:Delete CosmosDB document via Azure Functions UI通过 Azure Functions UI 删除 CosmosDB 文档
【发布时间】:2020-05-23 03:30:05
【问题描述】:

我一直在寻找,但找不到可以使用 Portal UI 删除 Cosmos DB 中元素的 Javascript 代码。

目前,我一直在使用 UI 来创建输入和输出绑定,并在我的 index.js 中进行读写:

context.bindings.inputDocument
context.bindings.outputDocument

inputDocument 给出了一个数组,然后我也可以通过给 outputDocument 一个数组来创建新文档。我应该在我的 index.js 中编写什么样的 Javascript 代码,或者是否有其他绑定来删除特定条目?

【问题讨论】:

    标签: javascript azure-functions azure-cosmosdb document function-binding


    【解决方案1】:

    你可以在这里找到 azure cosmosdb java 脚本文档azure-cosmos

    【讨论】:

      【解决方案2】:

      如您所见,Cosmos DB 绑定对于读/写很有用。对于删除操作,您需要手动使用 Cosmos DB 客户端。

      对于 Javascript,请检查 recommended way here:

      const cosmos = require('@azure/cosmos');
      const endpoint = process.env.COSMOS_ENDPOINT; // Use the name of the setting that contains your Endpoint
      const key = process.env.COSMOS_KEY; // Use the name of the setting that contains your Key
      const { CosmosClient } = cosmos;
      
      const client = new CosmosClient({ endpoint, key });
      // All function invocations also reference the same database and container.
      // If on the contrary you need to change the container based on the Trigger, then create the instance inside the Function
      const container = client.database("YourDatabase").container("YourContainer");
      
      module.exports = async function (context) {
          const item = container.item("id to delete", "partition key value for item");
          await item.delete();
      } 
      

      有关更多项目管理示例,请参阅official ones on the Cosmos JD SDK GitHub

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-01
        • 2018-10-09
        • 1970-01-01
        • 2017-11-30
        • 1970-01-01
        相关资源
        最近更新 更多