Cosmos DB-删除文档 [英] Cosmos DB - Deleting a document

查看:133
本文介绍了Cosmos DB-删除文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Cosmos DB中删除单个记录?

How can I delete an individual record from Cosmos DB?

我可以使用SQL语法进行选择:

I can select using SQL syntax:

SELECT *
FROM collection1
WHERE (collection1._ts > 0)

确保所有文档(类似于行?)都已返回

And sure enough all documents (analogous to rows?) are returned

但是,当我尝试删除时,这不起作用

However this doesn't work when I attempt to delete

DELETE
FROM collection1
WHERE (collection1._ts > 0)

我该如何实现?

推荐答案

DocumentDB API的SQL专用于查询.也就是说,它仅提供SELECT,而不提供UPDATEDELETE.

The DocumentDB API's SQL is specifically for querying. That is, it only provides SELECT, not UPDATE or DELETE.

完全支持这些操作,但需要REST(或SDK)调用.例如,使用.net,您将调用DeleteDocumentAsync()ReplaceDocumentAsync(),而在node.js中,这将是对deleteDocument()replaceDocument()的调用.

Those operations are fully supported, but require REST (or SDK) calls. For example, with .net, you'd call DeleteDocumentAsync() or ReplaceDocumentAsync(), and in node.js, this would be a call to deleteDocument() or replaceDocument().

在您的特定情况下,您可以运行SELECT来标识要删除的文档,然后对每个文档进行删除"调用(或者,出于效率和交易性的考虑,将要删除的文档数组传递到存储中过程).

In your particular scenario, you could run your SELECT to identify documents for deletion, then make "delete" calls, one per document (or, for efficiency and transactionality, pass an array of documents to delete, into a stored procedure).

这篇关于Cosmos DB-删除文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆