Author: mreutegg
Date: Thu Oct 9 07:20:01 2014
New Revision: 1630305
URL: http://svn.apache.org/r1630305
Log:
OAK-1990: Utility js methods to manage Oak data in Mongo
Add function to remove a subtree
Modified:
jackrabbit/oak/trunk/oak-run/src/main/js/oak-mongo.js
Modified: jackrabbit/oak/trunk/oak-run/src/main/js/oak-mongo.js
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/js/oak-mongo.js?rev=1630305&r1=1630304&r2=1630305&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/js/oak-mongo.js (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/js/oak-mongo.js Thu Oct 9 07:20:01
2014
@@ -172,6 +172,22 @@ var oak = (function(global){
return new Revision(rev).toReadableString();
}
+ /**
+ * Removes the complete subtree rooted at the given path.
+ */
+ api.removeDescendantsAndSelf = function(path) {
+ var count = 0;
+ var depth = pathDepth(path);
+ while (true) {
+ var result = db.nodes.remove({_id: pathFilter(depth++, path)});
+ if (result.nRemoved == 0) {
+ break;
+ }
+ count += result.nRemoved;
+ }
+ return {nRemoved : count};
+ }
+
//~--------------------------------------------------< internal >
var checkOrFixLastRevs = function(path, clusterId, dryRun) {