-1

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

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

context.bindings.inputDocument
context.bindings.outputDocument

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

4

2 回答 2

0

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

对于 Javascript,请在​​此处查看推荐的方式

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();
} 

更多项目管理示例,请参见Cosmos JD SDK GitHub 上的官方示例。

于 2020-02-10T16:23:40.823 回答
0

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

于 2020-02-08T03:04:45.780 回答