I have a MongoConnection to a mongos instance. Mongos internally connects to three shards. Is there any way using which I can get the individual connection each shards or at least get the info on the shards so that I can create new connections ?
I have looked at the MongoConnection class and didn't find anything related to mongos.
http://api.mongodb.org/ruby/1.3.1/Mongo/Connection.html
Mongo version 2.2 and MongoDriver 1.3.1 and language ruby
Eg:
Mongos is a localhost:27107
which has shards at 214.187.112.113:27107 , 209.117.116.103:27107 114.117.162.123:27107
Now My MongoConnection variable has connection to localhost:27107 is there a way from this connection I can create connections to individual shards # 214.187.11.113 etc
MongoDB cluster comes with 3 types of components
1.) Query Router(a mongos instance)
2.) Config server (a mongod instance
3.) Sharding servers (mongod instances)
Mongos is a sharding service provided by MomgoDB.
Mongo shard servers gets registered to config server via mongos.
sh.addShard( "mongo-shard-1:27017" )
sh.addShard( "mongo-shard-2:27017" )
When any request (read/write) comes to mongos, the mongos first gets shard information from config server and then serves that request by forwarding it to the appropriate sharding server(s).
As each shard server is also running mongod, you can connect to it directly but then it will serve as an independent MongoDB instance and will not be a part of cluster.
if you want to control sharding you can do it as follow.
https://www.linode.com/docs/databases/mongodb/build-database-clusters-with-mongodb
Related
I couldn't find any clear document that explains how to config multi mongos instances in a single sharded cluster with numbers of shards. I want to have more mongos and assign them to numbers of application servers to reduce latency.
You access a sharded cluster from a client via a mongos router.
Your cluster configuration can have many mongos routers (see Number of mongos and
Distribution). You connect from a client (e.g., a mongo shell) specifying multiple mongos's - and the client connects to the cluster using one of the mongos
(see: Connecting to a Sharded Cluster).
From a mongo shell client you use a connection string to connect to a MongoDB server. To connect to a sharded cluster specify mongos host(s) in the connection string using Standard ConnectionString Format; an example.
I've one primary host as mongo1.ppshein.net, secondary host as mongo1.ppshein.net and arbiter as mongo3.ppshein.net, and configured MongoDB replica as above shown in AWS EC2. And in each of MongoDB config file, bindIP is as its host name and App Server host.
To access that MongoDB replica from python, I thought I could be able to use following code-snippet,
>>> from pymongo import MongoClient
>>> db = MongoClient('mongodb://serverA:27017, serverB:27017, serverC:27017/?replicaSet=foo').db_name
But problem is if serverA is down/unhealthy, I'm not sure whether above code-snippet would be working properly or not. That's why I'm curious to know how to get primary host of MongoDB instead of adding multiple hosts in connection string?
Once you connect to a replica set the driver will always reconnect you to the primary if one can be elected (i.e. you have a quorum of nodes). the only reason you give a list of nodes in the argument is to prevent a situation where you are attempting to connect to a node that is down. if that node was down you would get a server timeout.
The full specification for the server discovery and monitoring protocol is here.
I am supposed to setup mongodb on 4 servers (a school project to benchmark mongodb, vs others). So I am thinking of using only sharding without replication. So I attempted to setup the 1st 3 server to run mongod --configsvr, and the 4th just a normal mongod instance. Then for all servers, I run mongos. Then I am at the part where I run sh.addShard("...") and I get
{
"ok" : 0,
"errmsg" : "the specified mongod is a --configsvr and should thus not be a shard server"
}
Seems like I cant have a config server running as a shard too? How then should I set things up?
No, the config server is not a shard. The config server is a special mongod instance that stores the sharded cluster metadata, essentially how the data is distributed across the sharded cluster.
You really only need 1 mongos instance for a simple setup like this. When you start mongos, you will provide it with the hostname(s) of your config server(s).
The Sharded Cluster Deployment Tutorial explains all of the steps that you need to follow.
I have set 3 MongoDB nodes in replication set - primary, secondary and arbiter.
I just want to know does arbiter node in Mongo Database has admin database by default when its configured.
Thanks
The arbiter does not contain any data therefore you or the application won't need to authenticate if you connect directly.
When your application is connecting to a replicaset it will detect if a node is an arbiter and don't attempt to connect to it.
Depending on the driver there could be exceptions (bugs) where the application could still attempt to authenticate to the arbiter.
we are going to use mongo db for an alert monitoring application.
We thought first to write the data to files and then to write it onto mongodb using mongoimport utility. Each file will have 1Mill records on an average.
Here my question is "shall we sharding here...?"
I guess mongoimport is not aware of sharding.
How does sharding works when writes are happening by mongoimport...?
If your collection exists and is sharded and you run mongoimport against a mongos router, then it will respect sharding rules (writes will be distributed according to chunk location).
Footnote
If you have a mongodb cluster, you have to have mongos daemon(s) in there. mongos reads your cluster configuration from config servers and knows where to route requests from your app. In a cluster configuration you should never talk to mongod servers directly, only via mongos. Read more about cluster configuration here.