3
// NOTE 'Mongo' may be defined here or in MongoJS.cpp. Add code to init, not to this constructor.
4
if ( typeof Mongo == "undefined" ){
5
Mongo = function( host ){
10
if ( ! Mongo.prototype ){
11
throw "Mongo.prototype not defined";
14
if ( ! Mongo.prototype.find )
15
Mongo.prototype.find = function( ns , query , fields , limit , skip ){ throw "find not implemented"; }
16
if ( ! Mongo.prototype.insert )
17
Mongo.prototype.insert = function( ns , obj ){ throw "insert not implemented"; }
18
if ( ! Mongo.prototype.remove )
19
Mongo.prototype.remove = function( ns , pattern ){ throw "remove not implemented;" }
20
if ( ! Mongo.prototype.update )
21
Mongo.prototype.update = function( ns , query , obj , upsert ){ throw "update not implemented;" }
23
if ( typeof mongoInject == "function" ){
24
mongoInject( Mongo.prototype );
27
Mongo.prototype.setSlaveOk = function() {
31
Mongo.prototype.getDB = function( name ){
32
return new DB( this , name );
35
Mongo.prototype.getDBs = function(){
36
var res = this.getDB( "admin" ).runCommand( { "listDatabases" : 1 } );
37
assert( res.ok == 1 , "listDatabases failed" );
41
Mongo.prototype.getDBNames = function(){
42
return this.getDBs().databases.map(
49
Mongo.prototype.getCollection = function(ns){
50
var idx = ns.indexOf( "." );
53
var db = ns.substring( 0 , idx );
54
var c = ns.substring( idx + 1 );
55
return this.getDB( db ).getCollection( c );
58
Mongo.prototype.toString = function(){
59
return "mongo connection to " + this.host;
62
connect = function( url , user , pass ){
63
chatty( "connecting to: " + url )
66
throw "you specified a user and not a password. either you need a password, or you're using the old connect api";
68
var idx = url.indexOf( "/" );
73
db = new Mongo().getDB( url );
75
db = new Mongo( url.substring( 0 , idx ) ).getDB( url.substring( idx + 1 ) );
78
if ( ! db.auth( user , pass ) ){
79
throw "couldn't login";