Azure DocumentDB 的截断等效命令
Truncate Equivalent command for Azure DocumentDB
我有一个 collection,其中包含 1000 多个 json 文档。我现在想删除 collection 中的所有文档。
是否有任何方法可以使用查询从门户网站执行此操作?
PS:我知道我可以删除 collection 和 re-create 它或使用 c# 应用程序来完成它。
不,DocumentDB 中没有与 SQL DELETE 表达式等效的表达式,因此无法通过查询来实现。这是一个存储过程 (CoffeeScript),当我想根据查询删除时,它会为我执行此操作。
deleteSomeDocuments = (memo) ->
collection = getContext().getCollection()
unless memo?
memo = {}
if memo.returnDeleted
unless memo.deleted?
memo.deleted = []
else
memo.returnDeleted = false
stillQueuingOperations = true
query = () ->
if stillQueuingOperations
responseOptions =
pageSize: memo.remaining
setBody()
if memo.filterQuery?
memo.stillQueueing = collection.queryDocuments(collection.getSelfLink(), memo.filterQuery, responseOptions, onReadDocuments)
else
memo.stillQueueing = collection.readDocuments(collection.getSelfLink(), responseOptions, onReadDocuments)
onReadDocuments = (err, resources, options) ->
if err
throw err
if resources.length isnt memo.remaining
throw new Error("Expected memo.remaining (#{memo.remaining}) and the number of rows returned (#{resources.length}) to match. They don't.")
memo.stillQueueing = true
while memo.remaining > 0 and memo.stillQueueing
oldDocument = resources[memo.remaining - 1]
documentLink = oldDocument._self
etag = oldDocument._etag
options = {etag} # Sending the etag per best practice, but not handling it if there is conflict.
getContext().getResponse().setBody(memo)
memo.stillQueueing = collection.deleteDocument(documentLink, options)
if memo.stillQueueing
if memo.returnDeleted
memo.deleted.push(oldDocument)
memo.remaining--
setBody = () ->
getContext().getResponse().setBody(memo)
query()
return memo
exports.deleteSomeDocuments = deleteSomeDocuments
我有一个 collection,其中包含 1000 多个 json 文档。我现在想删除 collection 中的所有文档。
是否有任何方法可以使用查询从门户网站执行此操作?
PS:我知道我可以删除 collection 和 re-create 它或使用 c# 应用程序来完成它。
不,DocumentDB 中没有与 SQL DELETE 表达式等效的表达式,因此无法通过查询来实现。这是一个存储过程 (CoffeeScript),当我想根据查询删除时,它会为我执行此操作。
deleteSomeDocuments = (memo) ->
collection = getContext().getCollection()
unless memo?
memo = {}
if memo.returnDeleted
unless memo.deleted?
memo.deleted = []
else
memo.returnDeleted = false
stillQueuingOperations = true
query = () ->
if stillQueuingOperations
responseOptions =
pageSize: memo.remaining
setBody()
if memo.filterQuery?
memo.stillQueueing = collection.queryDocuments(collection.getSelfLink(), memo.filterQuery, responseOptions, onReadDocuments)
else
memo.stillQueueing = collection.readDocuments(collection.getSelfLink(), responseOptions, onReadDocuments)
onReadDocuments = (err, resources, options) ->
if err
throw err
if resources.length isnt memo.remaining
throw new Error("Expected memo.remaining (#{memo.remaining}) and the number of rows returned (#{resources.length}) to match. They don't.")
memo.stillQueueing = true
while memo.remaining > 0 and memo.stillQueueing
oldDocument = resources[memo.remaining - 1]
documentLink = oldDocument._self
etag = oldDocument._etag
options = {etag} # Sending the etag per best practice, but not handling it if there is conflict.
getContext().getResponse().setBody(memo)
memo.stillQueueing = collection.deleteDocument(documentLink, options)
if memo.stillQueueing
if memo.returnDeleted
memo.deleted.push(oldDocument)
memo.remaining--
setBody = () ->
getContext().getResponse().setBody(memo)
query()
return memo
exports.deleteSomeDocuments = deleteSomeDocuments