mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 17:10:48 +01:00
better shell help
This commit is contained in:
parent
fcb5790e75
commit
7721712824
@ -1364,7 +1364,27 @@ const StringData _jscode_raw_utils =
|
||||
"};\n"
|
||||
"\n"
|
||||
"help = shellHelper.help = function (x) {\n"
|
||||
"if (x == \"connect\") {\n"
|
||||
"if (x == \"mr\") {\n"
|
||||
"print(\"\\nSee also http://www.mongodb.org/display/DOCS/MapReduce\");\n"
|
||||
"print(\"\\nfunction mapf() {\");\n"
|
||||
"print(\" // 'this' holds current document to inspect\");\n"
|
||||
"print(\" emit(key, value);\");\n"
|
||||
"print(\"}\");\n"
|
||||
"print(\"\\nfunction reducef(key,value_array) {\");\n"
|
||||
"print(\" return reduced_value;\");\n"
|
||||
"print(\"}\");\n"
|
||||
"print(\"\\ndb.mycollection.mapReduce(mapf, reducef[, options])\");\n"
|
||||
"print(\"\\noptions\");\n"
|
||||
"print(\"{[query : <query filter object>]\");\n"
|
||||
"print(\" [, sort : <sort the query. useful for optimization>]\");\n"
|
||||
"print(\" [, limit : <number of objects to return from collection>]\");\n"
|
||||
"print(\" [, out : <output-collection name>]\");\n"
|
||||
"print(\" [, keeptemp: <true|false>]\");\n"
|
||||
"print(\" [, finalize : <finalizefunction>]\");\n"
|
||||
"print(\" [, scope : <object where fields go into javascript global scope >]\");\n"
|
||||
"print(\" [, verbose : true]}\\n\");\n"
|
||||
"return;\n"
|
||||
"} if (x == \"connect\") {\n"
|
||||
"print(\"\\nNormally one specifies the server on the mongo shell command line. Run mongo --help to see those options.\");\n"
|
||||
"print(\"Additional connections may be opened:\\n\");\n"
|
||||
"print(\" var x = new Mongo('host[:port]');\");\n"
|
||||
@ -1412,6 +1432,7 @@ const StringData _jscode_raw_utils =
|
||||
"print(\"\\t\" + \"help connect connecting to a db help\");\n"
|
||||
"print(\"\\t\" + \"help admin administrative help\");\n"
|
||||
"print(\"\\t\" + \"help misc misc things to know\");\n"
|
||||
"print(\"\\t\" + \"help mr mapreduce help\");\n"
|
||||
"print();\n"
|
||||
"print(\"\\t\" + \"show dbs show database names\");\n"
|
||||
"print(\"\\t\" + \"show collections show collections in current database\");\n"
|
||||
@ -1421,7 +1442,7 @@ const StringData _jscode_raw_utils =
|
||||
"print(\"\\t\" + \"db.foo.find() list objects in collection foo\");\n"
|
||||
"print(\"\\t\" + \"db.foo.find( { a : 1 } ) list objects in foo where a == 1\");\n"
|
||||
"print(\"\\t\" + \"it result of the last line evaluated; use to further iterate\");\n"
|
||||
"print(\"\\t\" + \"DBQuery.shellBatchSize = x set default number of items to display on shell\" );\n"
|
||||
"print(\"\\t\" + \"DBQuery.shellBatchSize = x set default number of items to display on shell\");\n"
|
||||
"print(\"\\t\" + \"exit quit the mongo shell\");\n"
|
||||
"}\n"
|
||||
;
|
||||
|
227
shell/utils.js
227
shell/utils.js
@ -1294,47 +1294,47 @@ rs.help = function () {
|
||||
rs.slaveOk = function () { return db.getMongo().setSlaveOk(); }
|
||||
rs.status = function () { return db._adminCommand("replSetGetStatus"); }
|
||||
rs.isMaster = function () { return db.isMaster(); }
|
||||
rs.initiate = function (c) { return db._adminCommand({ replSetInitiate: c }); }
|
||||
rs.reconfig = function (cfg) {
|
||||
cfg.version = rs.conf().version + 1;
|
||||
var res = null;
|
||||
try {
|
||||
res = db.adminCommand({ replSetReconfig: cfg });
|
||||
}
|
||||
catch (e) {
|
||||
print("shell got exception during reconfig: " + e);
|
||||
print("in some circumstances, the primary steps down and closes connections on a reconfig");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
rs.add = function (hostport, arb) {
|
||||
var cfg = hostport;
|
||||
|
||||
var local = db.getSisterDB("local");
|
||||
assert(local.system.replset.count() <= 1, "error: local.system.replset has unexpected contents");
|
||||
var c = local.system.replset.findOne();
|
||||
assert(c, "no config object retrievable from local.system.replset");
|
||||
|
||||
c.version++;
|
||||
|
||||
var max = 0;
|
||||
for (var i in c.members)
|
||||
if (c.members[i]._id > max) max = c.members[i]._id;
|
||||
if (isString(hostport)) {
|
||||
cfg = { _id: max + 1, host: hostport };
|
||||
if (arb)
|
||||
cfg.arbiterOnly = true;
|
||||
}
|
||||
c.members.push(cfg);
|
||||
var res = null;
|
||||
try {
|
||||
res = db.adminCommand({ replSetReconfig: c });
|
||||
}
|
||||
catch (e) {
|
||||
print("shell got exception during reconfig: " + e);
|
||||
print("in some circumstances, the primary steps down and closes connections on a reconfig");
|
||||
}
|
||||
return res;
|
||||
rs.initiate = function (c) { return db._adminCommand({ replSetInitiate: c }); }
|
||||
rs.reconfig = function (cfg) {
|
||||
cfg.version = rs.conf().version + 1;
|
||||
var res = null;
|
||||
try {
|
||||
res = db.adminCommand({ replSetReconfig: cfg });
|
||||
}
|
||||
catch (e) {
|
||||
print("shell got exception during reconfig: " + e);
|
||||
print("in some circumstances, the primary steps down and closes connections on a reconfig");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
rs.add = function (hostport, arb) {
|
||||
var cfg = hostport;
|
||||
|
||||
var local = db.getSisterDB("local");
|
||||
assert(local.system.replset.count() <= 1, "error: local.system.replset has unexpected contents");
|
||||
var c = local.system.replset.findOne();
|
||||
assert(c, "no config object retrievable from local.system.replset");
|
||||
|
||||
c.version++;
|
||||
|
||||
var max = 0;
|
||||
for (var i in c.members)
|
||||
if (c.members[i]._id > max) max = c.members[i]._id;
|
||||
if (isString(hostport)) {
|
||||
cfg = { _id: max + 1, host: hostport };
|
||||
if (arb)
|
||||
cfg.arbiterOnly = true;
|
||||
}
|
||||
c.members.push(cfg);
|
||||
var res = null;
|
||||
try {
|
||||
res = db.adminCommand({ replSetReconfig: c });
|
||||
}
|
||||
catch (e) {
|
||||
print("shell got exception during reconfig: " + e);
|
||||
print("in some circumstances, the primary steps down and closes connections on a reconfig");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
rs.stepDown = function (secs) { return db._adminCommand({ replSetStepDown:secs||60}); }
|
||||
rs.freeze = function (secs) { return db._adminCommand({replSetFreeze:secs}); }
|
||||
@ -1356,66 +1356,87 @@ rs.remove = function (hn) {
|
||||
}
|
||||
|
||||
return "error: couldn't find "+hn+" in "+tojson(c.members);
|
||||
};
|
||||
|
||||
help = shellHelper.help = function (x) {
|
||||
if (x == "connect") {
|
||||
print("\nNormally one specifies the server on the mongo shell command line. Run mongo --help to see those options.");
|
||||
print("Additional connections may be opened:\n");
|
||||
print(" var x = new Mongo('host[:port]');");
|
||||
print(" var mydb = x.getDB('mydb');");
|
||||
print(" or");
|
||||
print(" var mydb = connect('host[:port]/mydb');");
|
||||
print("\nNote: the REPL prompt only auto-reports getLastError() for the shell command line connection.\n");
|
||||
return;
|
||||
}
|
||||
if (x == "misc") {
|
||||
print("\tb = new BinData(subtype,base64str) create a BSON BinData value");
|
||||
print("\tb.subtype() the BinData subtype (0..255)");
|
||||
print("\tb.length() length of the BinData data in bytes");
|
||||
print("\tb.hex() the data as a hex encoded string");
|
||||
print("\tb.base64() the data as a base 64 encoded string");
|
||||
print("\tb.toString()");
|
||||
return;
|
||||
}
|
||||
if (x == "admin") {
|
||||
print("\tls([path]) list files");
|
||||
print("\tpwd() returns current directory");
|
||||
print("\tlistFiles([path]) returns file list");
|
||||
print("\thostname() returns name of this host");
|
||||
print("\tcat(fname) returns contents of text file as a string");
|
||||
print("\tremoveFile(f) delete a file");
|
||||
print("\tload(jsfilename) load and execute a .js file");
|
||||
print("\trun(program[, args...]) spawn a program and wait for its completion");
|
||||
print("\tsleep(m) sleep m milliseconds");
|
||||
print("\tgetMemInfo() diagnostic");
|
||||
return;
|
||||
}
|
||||
if (x == "test") {
|
||||
print("\tstartMongodEmpty(args) DELETES DATA DIR and then starts mongod");
|
||||
print("\t returns a connection to the new server");
|
||||
print("\tstartMongodTest() DELETES DATA DIR");
|
||||
print("\t automatically picks port #s starting at 27000 and increasing");
|
||||
print("\t or you can specify the port as the first arg");
|
||||
print("\t dir is /data/db/<port>/ if not specified as the 2nd arg");
|
||||
print("\t returns a connection to the new server");
|
||||
return;
|
||||
}
|
||||
print("\t" + "db.help() help on db methods");
|
||||
print("\t" + "db.mycoll.help() help on collection methods");
|
||||
print("\t" + "rs.help() help on replica set methods");
|
||||
print("\t" + "help connect connecting to a db help");
|
||||
print("\t" + "help admin administrative help");
|
||||
print("\t" + "help misc misc things to know");
|
||||
print();
|
||||
print("\t" + "show dbs show database names");
|
||||
print("\t" + "show collections show collections in current database");
|
||||
print("\t" + "show users show users in current database");
|
||||
print("\t" + "show profile show most recent system.profile entries with time >= 1ms");
|
||||
print("\t" + "use <db_name> set current database");
|
||||
print("\t" + "db.foo.find() list objects in collection foo");
|
||||
print("\t" + "db.foo.find( { a : 1 } ) list objects in foo where a == 1");
|
||||
print("\t" + "it result of the last line evaluated; use to further iterate");
|
||||
print("\t" + "DBQuery.shellBatchSize = x set default number of items to display on shell" );
|
||||
print("\t" + "exit quit the mongo shell");
|
||||
};
|
||||
|
||||
help = shellHelper.help = function (x) {
|
||||
if (x == "mr") {
|
||||
print("\nSee also http://www.mongodb.org/display/DOCS/MapReduce");
|
||||
print("\nfunction mapf() {");
|
||||
print(" // 'this' holds current document to inspect");
|
||||
print(" emit(key, value);");
|
||||
print("}");
|
||||
print("\nfunction reducef(key,value_array) {");
|
||||
print(" return reduced_value;");
|
||||
print("}");
|
||||
print("\ndb.mycollection.mapReduce(mapf, reducef[, options])");
|
||||
print("\noptions");
|
||||
print("{[query : <query filter object>]");
|
||||
print(" [, sort : <sort the query. useful for optimization>]");
|
||||
print(" [, limit : <number of objects to return from collection>]");
|
||||
print(" [, out : <output-collection name>]");
|
||||
print(" [, keeptemp: <true|false>]");
|
||||
print(" [, finalize : <finalizefunction>]");
|
||||
print(" [, scope : <object where fields go into javascript global scope >]");
|
||||
print(" [, verbose : true]}\n");
|
||||
return;
|
||||
} if (x == "connect") {
|
||||
print("\nNormally one specifies the server on the mongo shell command line. Run mongo --help to see those options.");
|
||||
print("Additional connections may be opened:\n");
|
||||
print(" var x = new Mongo('host[:port]');");
|
||||
print(" var mydb = x.getDB('mydb');");
|
||||
print(" or");
|
||||
print(" var mydb = connect('host[:port]/mydb');");
|
||||
print("\nNote: the REPL prompt only auto-reports getLastError() for the shell command line connection.\n");
|
||||
return;
|
||||
}
|
||||
if (x == "misc") {
|
||||
print("\tb = new BinData(subtype,base64str) create a BSON BinData value");
|
||||
print("\tb.subtype() the BinData subtype (0..255)");
|
||||
print("\tb.length() length of the BinData data in bytes");
|
||||
print("\tb.hex() the data as a hex encoded string");
|
||||
print("\tb.base64() the data as a base 64 encoded string");
|
||||
print("\tb.toString()");
|
||||
return;
|
||||
}
|
||||
if (x == "admin") {
|
||||
print("\tls([path]) list files");
|
||||
print("\tpwd() returns current directory");
|
||||
print("\tlistFiles([path]) returns file list");
|
||||
print("\thostname() returns name of this host");
|
||||
print("\tcat(fname) returns contents of text file as a string");
|
||||
print("\tremoveFile(f) delete a file");
|
||||
print("\tload(jsfilename) load and execute a .js file");
|
||||
print("\trun(program[, args...]) spawn a program and wait for its completion");
|
||||
print("\tsleep(m) sleep m milliseconds");
|
||||
print("\tgetMemInfo() diagnostic");
|
||||
return;
|
||||
}
|
||||
if (x == "test") {
|
||||
print("\tstartMongodEmpty(args) DELETES DATA DIR and then starts mongod");
|
||||
print("\t returns a connection to the new server");
|
||||
print("\tstartMongodTest() DELETES DATA DIR");
|
||||
print("\t automatically picks port #s starting at 27000 and increasing");
|
||||
print("\t or you can specify the port as the first arg");
|
||||
print("\t dir is /data/db/<port>/ if not specified as the 2nd arg");
|
||||
print("\t returns a connection to the new server");
|
||||
return;
|
||||
}
|
||||
print("\t" + "db.help() help on db methods");
|
||||
print("\t" + "db.mycoll.help() help on collection methods");
|
||||
print("\t" + "rs.help() help on replica set methods");
|
||||
print("\t" + "help connect connecting to a db help");
|
||||
print("\t" + "help admin administrative help");
|
||||
print("\t" + "help misc misc things to know");
|
||||
print("\t" + "help mr mapreduce help");
|
||||
print();
|
||||
print("\t" + "show dbs show database names");
|
||||
print("\t" + "show collections show collections in current database");
|
||||
print("\t" + "show users show users in current database");
|
||||
print("\t" + "show profile show most recent system.profile entries with time >= 1ms");
|
||||
print("\t" + "use <db_name> set current database");
|
||||
print("\t" + "db.foo.find() list objects in collection foo");
|
||||
print("\t" + "db.foo.find( { a : 1 } ) list objects in foo where a == 1");
|
||||
print("\t" + "it result of the last line evaluated; use to further iterate");
|
||||
print("\t" + "DBQuery.shellBatchSize = x set default number of items to display on shell");
|
||||
print("\t" + "exit quit the mongo shell");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user