You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2015/05/20 14:21:04 UTC
svn commit: r1680540 - /jackrabbit/oak/trunk/oak-run/src/main/js/oak-mongo.js
Author: chetanm
Date: Wed May 20 12:21:03 2015
New Revision: 1680540
URL: http://svn.apache.org/r1680540
Log:
OAK-2887 - Add support for generating mongo export command to oak-mongo
Applying patch from Vikas Saurabh. Thanks!
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=1680540&r1=1680539&r2=1680540&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 Wed May 20 12:21:03 2015
@@ -555,6 +555,39 @@ var oak = (function(global){
return getRevisionEntry(doc, commitRootPath, revision);
};
+ /**
+ * Prints mongoexport command to export all documents related to given path.
+ * Related documents refer to all documents in the hierarchy and their split documents.
+ * e.g.
+ * > oak.printMongoExportCommand("/etc", {db: "aem-author"})
+ *
+ * @memberof oak
+ * @method printMongoExportCommand
+ * @param {string} path the path of the document.
+ * @param {object} options pass optional parameters for host, port, db, and filename
+ * @returns {string} command line which can be used to export documents using mongoexport
+ */
+
+ api.printMongoExportCommand = function (path, options) {
+ options = options || {};
+ var host = options.host || "127.0.0.1";
+ var port = options.port || "27017";
+ var db = options.db || "oak";
+ var filename = options.filename || "all-required-nodes.json"
+
+ var query = JSON.stringify(getDocAndHierarchyQuery(path));
+
+ var mongoExportCommand = "mongoexport"
+ + " --host " + host
+ + " --port " + port
+ + " --db " + db
+ + " --collection nodes"
+ + " --out " + filename
+ + " --query '" + query + "'";
+
+ return mongoExportCommand;
+ };
+
//~--------------------------------------------------< internal >
var checkOrFixDeepHistory = function(path, fix, prepare, verbose) {
@@ -901,5 +934,40 @@ var oak = (function(global){
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
};
+ var getDocAndHierarchyQuery = function (path) {
+ var paths = getHierarchyPaths(path);
+
+ var ins = [];
+ var ors = [];
+ paths.forEach(function (path) {
+ ins.push(pathDepth(path) + ':' + path);
+
+ var depth = pathDepth(path);
+ var splitDocRegex = '^' + (depth+2) + ':p' + path + (depth==0?'':'/');
+
+ ors.push({_id : {$regex : splitDocRegex}});
+ });
+
+ ors.push({_id : {$in : ins}});
+
+ return {$or : ors}
+ };
+
+ var getHierarchyPaths = function (path) {
+ var pathElems = path.split("/");
+ var lastPath = "";
+ var paths = ["/"];
+
+ pathElems.forEach(function (pathElem) {
+ //avoid empty path elems like "/".split("/")->["", ""] or "/a".split("/")->["", "a"]
+ if (pathElem != "") {
+ lastPath = lastPath + "/" + pathElem;
+ paths.push(lastPath);
+ }
+ });
+
+ return paths;
+ };
+
return api;
}(this));
\ No newline at end of file