Setup mongodb for mongo-connector - mongodb

Did I use the right setup for mongo-connector? I followed this steps here.
PS C:\mongodb\bin> mongod --port 27017 --dbpath C:\data\db --replSet rs0
Then I start C:\mongodb\bin\mongo.exe and typed rs.initiate() and rs.conf(). If I check the status I get two errors:
rs0:PRIMARY> rs.status()
Sat Jan 25 19:19:47.788 Socket say send() errno:10053 An established connection
was aborted by the software in your host machine. 127.0.0.1:27017
Sat Jan 25 19:19:47.803 Error: socket exception [SEND_ERROR] for 127.0.0.1:27017
at src/mongo/shell/query.js:78
Sat Jan 25 19:19:47.803 trying reconnect to 127.0.0.1:27017
Sat Jan 25 19:19:47.819 reconnect 127.0.0.1:27017 ok

Related

practical limit for the number of databases in mongodb

Can anyone say are if there is any practical limit for the number of databases in mongodb? I've started to have serious problems when I passed 120 databases. Simple things like :
> show dbs
Mon Feb 10 16:35:32 DBClientCursor::init call() failed
Mon Feb 10 16:35:32 query failed : admin.$cmd { listDatabases: 1.0 } to: 127.0.0.1:27017
Mon Feb 10 16:35:32 Error: error doing query: failed src/mongo/shell/collection.js:155
Mon Feb 10 16:35:32 trying reconnect to 127.0.0.1:27017
Mon Feb 10 16:35:32 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
>
Mon Feb 10 16:36:01 trying reconnect to 127.0.0.1:27017
Mon Feb 10 16:36:01 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
>
Mon Feb 10 16:37:01 trying reconnect to 127.0.0.1:27017
Mon Feb 10 16:37:01 reconnect 127.0.0.1:27017 ok
and
> getMemInfo()
{ "virtual" : 32, "resident" : 7 }
Mon Feb 10 16:39:00 DBClientCursor::init call() failed
Mon Feb 10 16:39:00 query failed : admin.$cmd { replSetGetStatus: 1.0, forShell: 1.0 } to: 127.0.0.1:27017
> shell
Mon Feb 10 16:39:38 ReferenceError: shell is not defined (shell):1
Mon Feb 10 16:39:38 trying reconnect to 127.0.0.1:27017
Mon Feb 10 16:39:38 reconnect 127.0.0.1:27017 ok
Yet the log file stayed enigmatic
What version of mongodb are you running on what host?
Here is a test on CenOS 6.5, mongodb 2.2 x86_64 direct from EPEL
Here is a sample python script that creates 1000 databases
from pymongo import MongoClient
mc = MongoClient()
for i in range(5000):
print i
mc['db%s'%(i)].test.insert({"test":True})
output:
...snip...
506
Traceback (most recent call last):
File "overload_mongo.py", line 6, in <module>
mc['db%s'%(i)].test.insert({"test":True})
File "/usr/lib64/python2.6/site-packages/pymongo/collection.py", line 357, in insert
continue_on_error, self.__uuid_subtype), safe)
File "/usr/lib64/python2.6/site-packages/pymongo/mongo_client.py", line 929, in _send_message
raise AutoReconnect(str(e))
pymongo.errors.AutoReconnect: [Errno 104] Connection reset by peer
There it is, looking at the log
ERROR: Uncaught std::exception: boost::filesystem::basic_directory_iterator constructor: Too many open files: "/index/bauman/db/_tmp/esort.1392056635.506/", terminating
The good ole too many open files problem
If you are on a enterprise linux platform, you can drop this file into /etc/security/limits.d/mongodb.conf and start a new session
mongodb hard nofile 99999
mongodb soft nofile 99999
mongodb hard nproc 99999
mongodb soft nproc 99999
I dont know how to achieve a similar result on windows.
The 'problem' lies in that MongoDB wants to memory map every single database file, so you need your hostOS to allow it to do so.
Same code as above
python overload_mongo.py
Output
...snip...
995
996
997
998
999
All better

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).

error during mongo db.shutdownServer()

I got the following error when I try to shutdown mongodb in my VM Ubuntu.
I am running 12.10 Ubuntu headless server.
The current Mongodb Shell Version is 2.0.6
use admin
switched to db admin
> db.shutdownServer()
Tue Dec 10 14:17:03 DBClientCursor::init call() failed
Tue Dec 10 14:17:03 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1
server should be down...
Tue Dec 10 14:17:03 trying reconnect to 127.0.0.1
Tue Dec 10 14:17:03 reconnect 127.0.0.1 ok
Tue Dec 10 14:17:03 Socket recv() errno:104 Connection reset by peer 127.0.0.1:27017
Tue Dec 10 14:17:03 SocketException: remote: 127.0.0.1:27017 error: 9001 socket exception [1] server [127.0.0.1:27017]
Tue Dec 10 14:17:03 DBClientCursor::init call() failed
Tue Dec 10 14:17:03 query failed : admin.$cmd { getlasterror: 1.0, w: 1.0 } to: 127.0.0.1
Tue Dec 10 14:17:03 Error: error doing query: failed shell/collection.js:151
What should I do?
My reason for trying to shut it down is because I want to update to mongo 2.2.
Please advise.
Although the messaging is confusing, this is actually expected behaviour if you shutdown via the mongo shell. Since you ran the db.shutdownServer() command through the mongo shell it can no longer connect to the server and this is essentially indicating the shell has been disconnected.
The mongo shell tries to automatically reconnect when you hit enter, which results in the messages like "trying to reconnect ...".
There is an open issue to improve this behaviour/messaging if you'd like to upvote/watch it: SERVER-5467.

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>

Mongo sharding without shutdown the existing mongo instance

I need to do sharding without shutdown or restart the existing mongo instance in the port 27017 .
I tried the following, (while the default port is running and mongo instance)
mongod --shardsvr --dbpath /var/lib/mongodb/dba --port 10001 > /var/log/mongodb/shardlog/sharda.log &
mongod --shardsvr --dbpath /var/lib/mongodb/dbb --port 10002 > /var/log/mongodb/shardlog/shardb.log &
mongod --configsvr --dbpath /var/lib/mongodb/config --port 20000 > /var/log/mongodb/shardlog/configdb.log &
mongos --configdb localhost:20000 > /var/log/mongodb/shardlog/mongos.log &
Then mongos log giving an error,
Thu Aug 23 14:44:36 [mongosMain] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
Thu Aug 23 14:44:36 [mongosMain] ERROR: addr already in use
mongos is running on port 20000 but why It's trying to connect the default 27017 port?
Can I start mongos with several shards without disturbing the existing mongo instance on port 27017 ?
From the the list of commands you have given, it looks like you have not told the mongos to start on a different port than default.
You would need to supply the --port argument for mongos to start on a different port.
Try: mongos --configdb localhost:20000 --port 10003
Note: mongos is not running on port 20000 as you have said above. You have the config server running on that port