0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00
mongodb/shell/mongo.js

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2009-01-27 04:19:15 +01:00
// mongo.js
2009-01-30 20:51:31 +01:00
// NOTE 'Mongo' may be defined here or in MongoJS.cpp. Add code to init, not to this constructor.
2009-01-27 04:19:15 +01:00
if ( typeof Mongo == "undefined" ){
Mongo = function( host ){
this.init( host );
}
}
Mongo.prototype.find = function( ns , query , fields , limit , skip ){ throw "find not implemented"; }
Mongo.prototype.insert = function( ns , obj ){ throw "insert not implemented"; }
Mongo.prototype.remove = function( ns , pattern ){ throw "remove not implemented;" }
Mongo.prototype.update = function( ns , query , obj ){ throw "update not implemented;" }
mongoInject( Mongo.prototype );
2009-01-30 20:51:31 +01:00
Mongo.prototype.setSlaveOk = function() {
this.slaveOk = true;
}
2009-01-27 04:19:15 +01:00
Mongo.prototype.getDB = function( name ){
return new DB( this , name );
}
Mongo.prototype.getDBs = function(){
var res = this.getDB( "admin" ).runCommand( { "listDatabases" : 1 } );
assert( res.ok == 1 , "listDatabases failed" );
return res;
}
Mongo.prototype.getDBNames = function(){
return this.getDBs().databases.map(
function(z){
return z.name;
}
);
}
Mongo.prototype.toString = function(){
return "mongo connection";
}
connect = function( url , user , pass ){
2009-01-29 18:02:32 +01:00
print( "connecting to: " + url )
2009-01-29 13:46:43 +01:00
2009-01-27 04:19:15 +01:00
if ( user && ! pass )
throw "you specified a user and not a password. either you need a password, or you're using the old connect api";
var idx = url.indexOf( "/" );
var db;
if ( idx < 0 )
db = new Mongo().getDB( url );
else
db = new Mongo( url.substring( 0 , idx ) ).getDB( url.substring( idx + 1 ) );
if ( user && pass ){
if ( ! db.auth( user , pass ) ){
throw "couldn't login";
}
}
return db;
}