我一直在寻找,但是找不到使用门户网站UI删除Cosmos DB中的元素的Javascript代码。
当前,我一直在使用UI创建输入和输出绑定,并在index.js中进行读写操作。
context.bindings.inputDocument
context.bindings.outputDocument
inputDocument提供了一个数组,然后我也可以通过给outputDocument提供一个数组来创建新文档。我应该在index.js中编写哪种Javascript代码,或者还有其他绑定来删除特定条目?
Cosmos DB绑定对于您发现的读/写很有用。对于删除操作,您需要手动使用Cosmos DB客户端。
对于Java语言,请检查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。
您可以在azure-cosmos中找到azure cosmosdb文档