什么是查询或其他快速删除集合中所有文档的方法?现在我正在删除整个集合并重新创建。如何通过查询浏览器清除DocumentDB中的集合
3
A
回答
0
目前,您正在执行的方法是通过Azure门户完成此操作的唯一方法。您可能想要考虑使用脚本或编码来实现一个工具来删除集合,而不是删除集合来完成。
+0
保存并执行按钮不工作。它是灰色的,只有“保存”的选项。这很愚蠢。 –
5
什么是查询或其他快速的方式来删除集合中的所有文件?
由于Chris Pietschmann提到它目前在Azure门户上不受支持,而此feature由Azure Documentdb团队查看。
我们可以用服务器端脚本(例如存储过程,udfs,触发器)做到这一点 我从另一个SO thread获得以下代码。它在我身边正常工作。
/**
* A DocumentDB stored procedure that bulk deletes documents for a given query.<br/>
* Note: You may need to execute this sproc multiple times (depending whether the sproc is able to delete every document within the execution timeout limit).
*
* @function
* @param {string} query - A query that provides the documents to be deleted (e.g. "SELECT * FROM c WHERE c.founded_year = 2008")
* @returns {Object.<number, boolean>} Returns an object with the two properties:<br/>
* deleted - contains a count of documents deleted<br/>
* continuation - a boolean whether you should execute the sproc again (true if there are more documents to delete; false otherwise).
*/
function bulkDeleteSproc(query) {
var collection = getContext().getCollection();
var collectionLink = collection.getSelfLink();
var response = getContext().getResponse();
var responseBody = {
deleted: 0,
continuation: true
};
// Validate input.
if (!query) throw new Error("The query is undefined or null.");
tryQueryAndDelete();
// Recursively runs the query w/ support for continuation tokens.
// Calls tryDelete(documents) as soon as the query returns documents.
function tryQueryAndDelete(continuation) {
var requestOptions = {continuation: continuation};
var isAccepted = collection.queryDocuments(collectionLink, query, requestOptions, function (err, retrievedDocs, responseOptions) {
if (err) throw err;
if (retrievedDocs.length > 0) {
// Begin deleting documents as soon as documents are returned form the query results.
// tryDelete() resumes querying after deleting; no need to page through continuation tokens.
// - this is to prioritize writes over reads given timeout constraints.
tryDelete(retrievedDocs);
} else if (responseOptions.continuation) {
// Else if the query came back empty, but with a continuation token; repeat the query w/ the token.
tryQueryAndDelete(responseOptions.continuation);
} else {
// Else if there are no more documents and no continuation token - we are finished deleting documents.
responseBody.continuation = false;
response.setBody(responseBody);
}
});
// If we hit execution bounds - return continuation: true.
if (!isAccepted) {
response.setBody(responseBody);
}
}
// Recursively deletes documents passed in as an array argument.
// Attempts to query for more on empty array.
function tryDelete(documents) {
if (documents.length > 0) {
// Delete the first document in the array.
var isAccepted = collection.deleteDocument(documents[0]._self, {}, function (err, responseOptions) {
if (err) throw err;
responseBody.deleted++;
documents.shift();
// Delete the next document in the array.
tryDelete(documents);
});
// If we hit execution bounds - return continuation: true.
if (!isAccepted) {
response.setBody(responseBody);
}
} else {
// If the document array is empty, query for more documents.
tryQueryAndDelete();
}
}
}
的更多细节的步骤做就天青门户如follwoing:
- 检查集合中的文件的数目
相关问题
- 1. 通过JavaScript清除浏览器
- 2. 如何从浏览器控制台查询我的MongoDB集合?
- 3. 如何清除浏览器的缓存?
- 4. 查询Azure DocumentDB中的子集合的子集合
- 5. 如何通过浏览器
- 6. 如何清除浏览器缓存?
- 7. .htaccess - 如何清除浏览器缓存?
- 8. Django通过集合查询
- 9. Nightwatch清除浏览器
- 10. 如何清除浏览器历史清除缓存?
- 11. 清除浏览器中的内存
- 12. 使用查询字符串方法清除浏览器缓存
- 13. Visual Studio 2010数据库浏览器sql查询清除表
- 14. 通过命令行清除浏览器缓存
- 15. 清除浏览器CSS缓存通过javascript调整大小
- 16. 通过Asp.net-C清除浏览器历史记录#
- 17. 如何清除WordPress中的服务器和浏览器缓存
- 18. 查询浏览器
- 19. NotifyCollectionChangedEventHandler - 如何清除集合
- 20. 通过浏览器
- 21. 通过浏览器
- 22. 通过浏览器
- 23. 如何从DocumentDb中的集合中删除文档?
- 24. SPARQL中的递归查询浏览集合
- 25. 在所有主流浏览器中清除浏览数据
- 26. 如何清除Android浏览器中的图标缓存?
- 27. 如何清除asp.net/javascript中的浏览器缓存?
- 28. 如何在我的Selenium测试中清除浏览器缓存
- 29. 如何使用MySQL查询浏览器
AFAIK,有没有其他办法可以做到这一点从门户。 – Mikhail
如果有用,请将其标记为答案,以帮助有更多问题的社区。 –
乌尔答案将帮助用户这就是为什么我upvoted它,但1)你的答案不符合快速简短的方式2)我希望有一些正式的方式来做到这一点(这仍在进展中)...所以我将保持打开状态直至时间 – JerryGoyal