0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

shell stuff

This commit is contained in:
Dwight 2010-06-07 11:17:08 -04:00
parent ac3c063d90
commit 370f9a1bd2
7 changed files with 87 additions and 28 deletions

View File

@ -1508,10 +1508,10 @@ namespace mongo {
for ( uintN i=0; i<argc; i++ ){
string filename = c.toString( argv[i] );
cout << "should load [" << filename << "]" << endl;
cout << "load [" << filename << "]" << endl;
if ( ! s->execFile( filename , false , true , false ) ){
JS_ReportError( cx , ((string)"error loading file: " + filename ).c_str() );
JS_ReportError( cx , ((string)"error loading js file: " + filename ).c_str() );
return JS_FALSE;
}
}

View File

@ -66,7 +66,7 @@ void shellHistoryInit(){
//rl_attempted_completion_function = my_completion;
#else
cout << "type \"exit\" to exit" << endl;
//cout << "type \"exit\" to exit" << endl;
#endif
}
void shellHistoryDone(){
@ -432,7 +432,7 @@ int _main(int argc, char* argv[]) {
mongo::UnitTest::runTests();
if ( !nodb ) { // connect to db
if ( ! mongo::cmdLine.quiet ) cout << "url: " << url << endl;
//if ( ! mongo::cmdLine.quiet ) cout << "url: " << url << endl;
stringstream ss;
if ( mongo::cmdLine.quiet )

View File

@ -219,6 +219,13 @@
</ItemGroup>
<ItemGroup>
<None Include="..\..\SConstruct" />
<None Include="..\collection.js" />
<None Include="..\db.js" />
<None Include="..\mongo.js" />
<None Include="..\mr.js" />
<None Include="..\query.js" />
<None Include="..\servers.js" />
<None Include="..\utils.js" />
<None Include="mongo.ico" />
</ItemGroup>
<ItemGroup>

View File

@ -33,6 +33,9 @@
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="_js files">
<UniqueIdentifier>{473e7192-9f2a-47c5-ad95-e5b75d4f48f9}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\dbshell.cpp">
@ -216,6 +219,27 @@
<None Include="mongo.ico">
<Filter>Resource Files</Filter>
</None>
<None Include="..\collection.js">
<Filter>_js files</Filter>
</None>
<None Include="..\db.js">
<Filter>_js files</Filter>
</None>
<None Include="..\mongo.js">
<Filter>_js files</Filter>
</None>
<None Include="..\mr.js">
<Filter>_js files</Filter>
</None>
<None Include="..\query.js">
<Filter>_js files</Filter>
</None>
<None Include="..\servers.js">
<Filter>_js files</Filter>
</None>
<None Include="..\utils.js">
<Filter>_js files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Library Include="..\..\..\js\js32d.lib" />

View File

@ -94,10 +94,11 @@ startMongos = function(){
return startMongoProgram.apply( null, createMongoArgs( "mongos" , arguments ) );
}
// Start a mongo program instance (generally mongod or mongos) and return a
// 'Mongo' object connected to it. This function's first argument is the
// program name, and subsequent arguments to this function are passed as
// command line arguments to the program.
/* Start mongod or mongos and return a Mongo() object connected to there.
This function's first argument is "mongod" or "mongos" program name, \
and subsequent arguments to this function are passed as
command line arguments to the program.
*/
startMongoProgram = function(){
var port = _parsePort.apply( null, arguments );
@ -132,15 +133,15 @@ myPort = function() {
return 27017;
}
ShardingTest = function( testName , numServers , verboseLevel , numMongos , otherParams ){
ShardingTest = function( testName , numShards , verboseLevel , numMongos , otherParams ){
if ( ! otherParams )
otherParams = {}
this._connections = [];
if ( otherParams.sync && numServers < 3 )
if ( otherParams.sync && numShards < 3 )
throw "if you want sync, you need at least 3 servers";
for ( var i=0; i<numServers; i++){
for ( var i=0; i<numShards; i++){
var conn = startMongodTest( 30000 + i , testName + i );
this._connections.push( conn );
}
@ -593,7 +594,6 @@ ToolTest.prototype.runTool = function(){
runMongoProgram.apply( null , a );
}
ReplTest = function( name, ports ){
this.name = name;
this.ports = ports || allocatePorts( 2 );
@ -614,7 +614,6 @@ ReplTest.prototype.getPath = function( master ){
return p;
}
ReplTest.prototype.getOptions = function( master , extra , putBinaryFirst, norepl ){
if ( ! extra )

View File

@ -115,7 +115,10 @@ namespace mongo {
#ifndef MONGO_SAFE_SHELL
BSONObj listFiles(const BSONObj& args){
BSONObj listFiles(const BSONObj& _args){
static BSONObj cd = BSON( "0" << "." );
BSONObj args = _args.isEmpty() ? cd : _args;
uassert( 10257 , "need to specify 1 argument to listFiles" , args.nFields() == 1 );
BSONObjBuilder lst;
@ -159,6 +162,24 @@ namespace mongo {
return ret.obj();
}
BSONObj ls(const BSONObj& args) {
BSONObj o = listFiles(args);
if( !o.isEmpty() ) {
for( BSONObj::iterator i = o.firstElement().Obj().begin(); i.more(); ) {
BSONObj f = i.next().Obj();
cout << f["name"].String();
if( f["isDirectory"].trueValue() ) cout << '/';
cout << '\n';
}
cout.flush();
}
return BSONObj();
}
BSONObj pwd(const BSONObj&) {
boost::filesystem::path p = boost::filesystem::current_path();
return BSON( "" << p.string() );
}
BSONObj removeFile(const BSONObj& args){
uassert( 12597 , "need to specify 1 argument to listFiles" , args.nFields() == 1 );
@ -694,6 +715,8 @@ namespace mongo {
//can't access filesystem
scope.injectNative( "removeFile" , removeFile );
scope.injectNative( "listFiles" , listFiles );
scope.injectNative( "ls" , ls );
scope.injectNative( "pwd", pwd );
scope.injectNative( "resetDbpath", ResetDbpath );
scope.injectNative( "copyDbpath", CopyDbpath );
#endif

View File

@ -762,20 +762,26 @@ shellHelper = function( command , rest , shouldPrint ){
shellPrintHelper( res );
}
return res;
}
help = shellHelper.help = function(){
print( "HELP" );
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 curent database to <db name>" );
print( "\t" + "db.help() help on DB methods");
print( "\t" + "db.foo.help() help on collection methods");
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");
}
help = shellHelper.help = function (x) {
if (x=="more") {
print("\tls()");
print("\tpwd()");
print("\tlistFiles()");
return;
}
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 curent database to <db name>");
print("\t" + "db.help() help on DB methods");
print("\t" + "db.foo.help() help on collection methods");
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" + "exit quit the mongo shell");
}
shellHelper.use = function( dbname ){