JavaScript execution failed connected to mongoHQ shell - mongodb

Trying to access MongoHQ directly:
> mongo mongodb://heroku:mypassword#alex.mongohq.com:10046/myapp
MongoDB shell version: 2.4.3
connecting to: mongodb://heroku:mypassword#alex.mongohq.com:10046/myapp
Tue Jun 4 16:10:09.255 Assertion failure _setName.size() src/mongo/client/dbclientinterface.h 211
0x10017116b 0x100135396 0x100068356 0x100129bab 0x10010f92f 0x10024b2fa 0x139ba3a06362 0x139ba3a0ce93 0x139ba3a400c9 0x139ba3a0c76e
0 mongo 0x000000010017116b _ZN5mongo15printStackTraceERSo + 43
1 mongo 0x0000000100135396 _ZN5mongo12verifyFailedEPKcS1_j + 310
2 mongo 0x0000000100068356 _ZN5mongo16ConnectionString5parseERKSsRSs + 1878
3 mongo 0x0000000100129bab _ZN5mongo17mongoConsExternalEPNS_7V8ScopeERKN2v89ArgumentsE + 187
4 mongo 0x000000010010f92f _ZN5mongo7V8Scope10v8CallbackERKN2v89ArgumentsE + 175
5 mongo 0x000000010024b2fa _ZN2v88internalL30Builtin_HandleApiCallConstructENS0_12_GLOBAL__N_116BuiltinArgumentsILNS0_21BuiltinExtraArgumentsE1EEEPNS0_7IsolateE + 618
6 ??? 0x0000139ba3a06362 0x0 + 21559186056034
7 ??? 0x0000139ba3a0ce93 0x0 + 21559186083475
8 ??? 0x0000139ba3a400c9 0x0 + 21559186292937
9 ??? 0x0000139ba3a0c76e 0x0 + 21559186081646
Tue Jun 4 16:10:09.264 JavaScript execution failed: Error: assertion src/mongo/client/dbclientinterface.h:211 at src/mongo/shell/mongo.js:L114
exception: connect failed
What's to be done?

This is a shell bug and it's not a new one. Basically the mongo shell doesn't accept the same format of connection string that regular mongodb drivers do. I can reproduce this error in the current and previous versions and this syntax isn't expected to work (though it probably shouldn't crash either, but there is already a bug for the shell to accept standard connection string: jira.mongodb.org/browse/SERVER-3254
Meanwhile you can connect by using the mongo shell options such as
mongo -u <user> -p <passwd> hostIP:port/db
or
mongo --host host --port port [ other options ] db

Just see if you have $ in your password, in that scenario enclose your password with ' ' then try to connect.
e.g.
mongo mongodb://host:port/authdb -username
dbusername -p 'password$123'

Related

mongodb: UnknownError assertion src/mongo/db/server_options_helpers.cpp:355

I was running mongodb without any issues until now. I don't really know what happened, as don't remember doing nothing weird. Still, now I get the following error when I try to launch the mongo server.
$ mongod --config /usr/local/etc/mongod.conf
2015-01-22T13:58:04.153+0100 Assertion failure getcwd(buffer, 1000) src/mongo/db/server_options_helpers.cpp 355
2015-01-22T13:58:04.169+0100 0x1017ae5aa 0x101759135 0x101745bf2 0x1015509ed 0x10132b7a3 0x100fd2be6 0x100fc5291 0x100fd60be 0x100fd68ae 0x100fc41eb 0x7fff8aff35c9
0 mongod 0x00000001017ae5aa _ZN5mongo15printStackTraceERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEE + 58
1 mongod 0x0000000101759135 _ZN5mongo10logContextEPKc + 453
2 mongod 0x0000000101745bf2 _ZN5mongo12verifyFailedEPKcS1_j + 626
3 mongod 0x00000001015509ed _ZN5mongo18storeServerOptionsERKNS_17optionenvironment11EnvironmentERKNSt3__16vectorINS4_12basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS9_ISB_EEEE + 10237
4 mongod 0x000000010132b7a3 _ZN5mongo18storeMongodOptionsERKNS_17optionenvironment11EnvironmentERKNSt3__16vectorINS4_12basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS9_ISB_EEEE + 35
5 mongod 0x0000000100fd2be6 _ZN5mongo45_mongoInitializerFunction_MongodOptions_StoreEPNS_18InitializerContextE + 38
6 mongod 0x0000000100fc5291 _ZN5boost6detail8function17function_invoker1IPFN5mongo6StatusEPNS3_18InitializerContextEES4_S6_E6invokeERNS1_15function_bufferES6_ + 17
7 mongod 0x0000000100fd60be _ZNK5mongo11Initializer7executeERKNSt3__16vectorINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS6_IS8_EEEERKNS1_3mapIS8_S8_NS1_4lessIS8_EENS6_INS1_4pairIKS8_S8_EEEEEE + 270
8 mongod 0x0000000100fd68ae _ZN5mongo21runGlobalInitializersEiPKPKcS3_ + 526
9 mongod 0x0000000100fc41eb main + 331
10 libdyld.dylib 0x00007fff8aff35c9 start + 1
2015-01-22T13:58:04.177+0100 SEVERE: Failed global initialization: UnknownError assertion src/mongo/db/server_options_helpers.cpp:355
I've tried running mongo --repair too, but got the same error.
This is weird!
I'm on OSX, using iTerm where I've tried to run the above process. Once I've quite iTerm, and restarted it, the created shell could run the process without any problems.
It seems as the process could not stop previously. Before, I even tried running mongo to see if I can connect, but it failed.

Error during mongo startup

When I type mongo on command prompt than output like
~$ mongo
MongoDB shell version: 2.2.3
connecting to: test
But when I type mongo 127.0.0.1:28017/stu1
output :-
MongoDB shell version: 2.2.3
connecting to: 127.0.0.1:28017/stu1
Mon Mar 10 16:56:01 DBClientCursor::init call() failed
Mon Mar 10 16:56:01 Error: Error during mongo startup. :: caused by :: 10276
DBClientBase::findN: transport error: 127.0.0.1:28017 ns: admin.$cmd query: { whatsmyuri: 1 } src/mongo/shell/mongo.js:93
exception: connect failed
OS :- ubuntu 12.04
So please help me to solve this error.
28017 is the default port for the HTTP admin interface, so if your config is allowing HTTP, you should use a web browser to access it http://127.0.0.1:28017/
You're trying to use mongo shell to access HTTP service.
To have access to the database using HTTP protocol then use ~$ mongod --rest to start the db. Now call http://127.0.0.1:28017/stu1/coll_name in the web browser which list all the documents in your collection.

Executing a JavaScript in MongoDB

I am trying to execute a Java script file in MongoDB at port 5930. Mongo can listen to the Database on that port:
./mongo localhost:5930
connecting to: localhost:5930/test
Server has startup warnings:
Wed Dec 18 13:15:58.906 [initandlisten]
Wed Dec 18 13:15:58.906 [initandlisten] ** WARNING: /proc/sys/vm/overcommit_memory is 2
Wed Dec 18 13:15:58.906 [initandlisten] ** Journaling works best with it set to 0 or 1
Now when I execute test.js at port 5930 but I get the following error:
./mongo test.js
connecting to: test
Wed Dec 18 13:22:56.011 JavaScript execution failed: Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112
exception: connect failed
The test.js has the following line:
conn = new Mongo("localhost:5930);
How can I run the script at port 5930? and Why did the script always try to execute from the default port (27017)?
Thanks
Mongo tries to connect itself to the local database automatically, before it looks at your script.
Connect to a local Mongo database running on an alternate port with this mongo command line:
mongo --nodb test.js
And have your code open the connection (which you already do).

Can't connect to mongodb locally even though mongod is running

I am unable to connect to my mongo database via external APIs or the mongo client locally, but can connect without issues from a remote host.
I have started mongod and can confirm that the server is running by visiting 127.0.0.1:27017
I have followed this answer with no luck
I have tried creating an entirely new database directory for mongo to generate a new set of database files, still no luck - so it's not a lock file or permissions issue.
$ mongo --verbose
MongoDB shell version: 2.4.4
Mon Jun 24 20:11:08.764 versionArrayTest passed
connecting to: test
Mon Jun 24 20:11:08.847 creating new connection to:127.0.0.1:27017
Mon Jun 24 20:11:08.847 BackgroundJob starting: ConnectBG
Mon Jun 24 20:12:11.848 JavaScript execution failed: Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112
Mon Jun 24 20:12:11.848 User Assertion: 12513:connect failed
exception: connect failed
I am running Ubuntu 12.04, I have installed mongo from the 10gen repo. Everything was running flawlessly originally, but after restarting the server, mongo fails to connect.
My netstat returns:
$ netstat -nap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:28017 0.0.0.0:* LISTEN -
I gotten the same problem on CentOs 6.4 (Mongo 2.4.5, but actually it happens in other versions too). There is weird threading issue. I debugged mongo and found workaround. It is required mongo recompile. It looks like timed_wait method from boost library returns timeout when spurious wake up happened. I am not sure where bug is: mongo, boost, glibc, linux kernel.
Mongo 2.4.5
Replace in src/mongo/util/background.cpp method BackgroundJob::wait
bool BackgroundJob::wait( unsigned msTimeOut ) {
verify( !_status->deleteSelf ); // you cannot call wait on a self-deleting job
scoped_lock l( _status->m );
boost::system_time const endTime = boost::get_system_time()+ boost::posix_time::milliseconds(msTimeOut);
if ( msTimeOut ) {
while ( _status->state != Done ) {
if ( ! _status->finished.timed_wait( l.boost() , endTime ) ){
boost::system_time const curTime=boost::get_system_time();
if((curTime - endTime).total_milliseconds()>0){
return false;
}
else {
LOG( LL_WARNING ) << "backgroundjob " << name() << "warning: spurious wakeup return TIMEOUT code but we want wait "<<(endTime-curTime).total_milliseconds()<<" ms yet! Try again." << endl;
}
}
}
}
else {
while ( _status->state != Done ) {
_status->finished.wait( l.boost() );
}
}
return true;
}
After some time I found other problem with Perl:
perl -MCPAN -e 'install "DateTime"'
Simple Perl test failed:
use strict;
use warnings;
use Test::More;
use DateTime;
{
my $epochtest = DateTime->from_epoch( epoch => '997121000' );
is(
$epochtest->epoch, 997121000,
"epoch method returns correct value"
);
}
I discovered that the problems with Perl and Mongo disappear if I remove /etc/localtime file!
I had the same issue running mongod 3.0.2 on Ubuntu 14.04:
MongoDB shell version: 2.4.9
Sun Apr 26 00:57:31.604 versionArrayTest passed
connecting to: xxx.xxx.xxx.xxx:27000/test
Sun Apr 26 00:57:31.667 creating new connection to:xxx.xxx.xxx.xxx:27000
Sun Apr 26 00:57:31.667 BackgroundJob starting: ConnectBG
Sun Apr 26 00:57:31.668 connected connection!
Sun Apr 26 00:57:31.671 User Assertion: 18:{ ok: 0.0, errmsg: "auth failed", code: 18 }
Sun Apr 26 00:57:31.673 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:228
Sun Apr 26 00:57:31.673 User Assertion: 12514:login failed
Sun Apr 26 00:57:31.673 freeing 1 uncollected N5mongo20DBClientWithCommandsE objects
exception: login failed
The distribution came from MMS Mongo:
https://mms.mongodb.com/
I then noticed on my MMS page, under mongod processes -> elipse menu;
a menu called:
"Connect to this Mongod Instance"
which returned a string:
"/var/lib/mongodb-mms-automation/mongodb-linux-x86_64-3.0.2/bin/mongo RBX1:27000"
(RBX1 being my instance and 27000 being the port I set)
Once I applied this string in my shell (I added extra user / password and authenticationDatabase parameters, and it worked.
I can now connect to my Mongod instance both locally and remotely.
Did you install MongoDB through MMS?

Mongodb client intermittent connection error

I have a replicaset where there is one primary and two secondary nodes.
Once in a while I am not able to connect to primary and i get this error which goes away after a minute or so and I am able to connect. Any thoughts why this could be happening ?
When this error happens I tried connecting to secondary and did rs.status which said
primary is still same server and running ok.
Below is the command text from the console that shows the issue.
mongo --host <hostname> --port 27017
MongoDB shell version: 2.2.2
connecting to: <hostname>:27017/test
Sat Mar 2 14:54:02 DBClientCursor::init call() failed
Sat Mar 2 14:54:02 Error: Error during mongo startup. :: caused by :: 10276 DBClientBase::findN: transport error: <hostname>:27017 ns: admin.$cmd query: { whatsmyuri: 1 } src/mongo/shell/mongo.js:93
exception: connect failed
mongo --host <hostname> --port 27017
MongoDB shell version: 2.2.2
connecting to: <hostname>:27017/test
rs0:PRIMARY>