正如您所发现的,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 上的官方示例。