Cosmos DB - 删除文档 [英] Cosmos DB - Deleting a document
问题描述
如何从 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
,不提供UPDATE
或DELETE
.
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屋!