Does arbiter node in mongodb has admin database - mongodb

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.

Related

How to find primary host of MongoDB replica and access in Python

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.

Mongodb replication automatically

Is there any ways or methods to start mongodb replication directly when mongod service start? I don't want to enter to shell and ON the replication?
Thanks!
You can create a mongod service which starts automatically when server starts.
First you need to create a configuration file(mongodb.conf) which will include configuration settings such as replicaSet name etc. Then create a service and install it using following command
mongod -f c:\mongod.conf --install
Then start the service using
net start mongodb
Read about configuration file here and
How to install mongo as service here
When you create a valid replica set in mongodb, your data will be asynchronously from the primary member to the secondary members in replica set
Having said that, you're not required to do extra efforts manually to get data replication done
When you do rs.slaveOk() on secondary, that allows you to query data from secondary members in the replica set.
It's a provision. It allows you to read from secondary provided that you're can tolerate the possible eventual consistent data. The replication does not happen when you do rs.slaveOk() on secondary
I'm not sure to understand. Your question was about service start. On my part, I install mongo on ubuntu and the service is not started with replicatet mode.
Finally, I disabled the first one and I created another service with the option --replSet myReplicat .
When you have only 2 servers, there is a problem with majority votes. On my part, I had 2 secondary after I stopped the primary and it was difficult to comeback with 1 primary and 1 secondary.
Effectively, the replication is always active. By default, all connections should go to the Primary. If you want to readonly from a secondary, you first enter the commande rs.slaveOk(). This command is active at session level. If you reconnect, you have to pass it again. It is not possible to put it at server side.

How to create mongodb oplog for database?

Recently I purchased cluster account from MongoDB atlas. I had checked UI and MongoDB documentation but don't know create oplog db. And how to create a connection string for oplog?
Oplog collection is automatically created and maintained by mongoDB and is created under the local database. It is used internally by mongoDB to maintain the various nodes in sync in a replica set. Assume you have a three node replica set, one primary and two secondary. When a write operation happens in the primary, the event is logged in oplog collection and is used internally to replicate the same change in the secondary nodes.
So to use oplog you will need a MongoDB server configured as a replica set. Standalone instances of mongoDB do not have oplog as there is no need for replication in this case.
However, you may start a standalone instance as a replica set by using the command,
Start Mongo server in replica mode.
mongod --dbPath <path_to_data_file> --replSet rs0
Initiate the replica set.(Execute from mongo shell)
rs.initiate();
oplog is a mongodb replication feature. If you have choose replication cluster, you have it in the database named "local". See the collections in "local" database.

Getting data from standalone into existing replica set without downtime

I have a standlone mongo instance running on AWS and now I created managed replica set using the mongo cloud manager (hosted on AWS as well). No I would like to get my data over from the standalone instance into the replica set if possible without downtime.
Shutting down all services generating a backup of the standalone instance and importing this into the replica set might be the possibility with a downtime.
If I add the standalone node as another replica set member to the new replica set what will happen then? will my standalone instance content be deleted? Or will this be synced to all other replica set hosts as well?
To increase security you need to have 3 systems in replica set (primary, secondary and secondary OR arbiter), having only pri/sec would cause more issues than expected.
if you server (primary) is not started with replica set parameter activated
mongod --replSet "rs0"
then, you need to add entry in config file or add startup parameter --replSet "myReplSet" - and this will cause a breakdown in your service.
then using manual from mongo you can go via steps and initiate single server replica set, then add secondary system.

getting shards under a mongos

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