[SERVER-9863] JavaScript execution failed after db.getSiblingDB() Created: 05/Jun/13  Updated: 16/Nov/21  Resolved: 05/Jun/13

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.4.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: David Verdejo Assignee: Unassigned
Resolution: Done Votes: 0
Labels: execution, failed, javascript, mongo
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Wed Jun 05 10:57:32.561 [initandlisten] db version v2.4.4
Wed Jun 05 10:57:32.561 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49


Attachments: PNG File mongod244.PNG    
Issue Links:
Related
related to DOCS-1568 Docs for getSiblingDB() do not mentio... Closed
Operating System: ALL
Steps To Reproduce:

use test
db.test.insert(

{t:1}

)
db.test.find()
db.getSiblingDB()

Participants:

 Description   

We create a new test instance with mongo 2.4.4 and after we execute "db.getSiblingDB()", we see the following error:

Wed Jun 05 11:06:53.529 JavaScript execution failed: Error: db initializer called with undefined argument at src/mongo/shell/mongo.js:L40



 Comments   
Comment by Tad Marshall [ 05/Jun/13 ]

Filed DOCS-1568.

Comment by Tad Marshall [ 05/Jun/13 ]

I filed DOCS-1568 to improve the documentation at http://docs.mongodb.org/manual/reference/method/db.getSiblingDB/ to describe the required parameter.

Comment by David Verdejo [ 05/Jun/13 ]

Sorry, my fault because I don't see the param name.

Comment by Tad Marshall [ 05/Jun/13 ]

Hi David,

The getSiblingDB() shell helper function takes a string argument containing the name of the database you want to reference. Since you did not provide a string, the constructor for the DB object received the JavaScript type 'undefined' for the database name, resulting in the error.

You can see the code for shell helper functions by typing the command without the parentheses:

> db.getSiblingDB
function ( name ){
    return this.getMongo().getDB( name );
}

The helper function is passing your argument (if any) to the getDB function, which is also a shell helper function, as is getMongo:

> db.getMongo
function (){
    assert( this._mongo , "why no mongo!" );
    return this._mongo;
}
> db.getMongo().getDB
function ( name ){
    if (jsTest.options().keyFile && ((typeof this.authenticated == 'undefined') || !this.authenticated)) {
        jsTest.authenticate(this)
    }
    return new DB( this , name );
}

Is your bug report asking for different behavior from this command, or a more diagnostic error message, or something else?

Tad

Generated at Thu Feb 08 03:21:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.