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.
Related
In Oracle developers can run sqls in nologging mode. Is it possible on Mongo DB or Mongo DB writes all operations into the oplog(operations log)?
A standalone server (not part of replica set or sharded cluster) does not employ the oplog.
I'm new to MongoDB, however I have setup a shard cluster with 3 replica sets. Each replica set has 2 mongod instances. I have a separate config server and 1 mongos instance.
I wanted to try whether it's possible to import documents to a particular/targeted shard, when the collection is not shard enabled. (As far as I know, we can't control in which shard the collection will get saved when importing is done via mongos instance)
Hence, I imported the documents using below command, and it was successful (followed this);
mongoimport --db NormalTestDB --collection TestDams --host <replSetName>/<hostname1><:port>,<hostname2><:port> --jsonArray --file “<path_to_json>”
(I used a particular replica set name in <replSetName>)
Now when I try this simple query db.TestDams.find().count() in mongos shell (by connecting to NormalTestDB), it returns 0. But if I try the same query by directly connecting to the Primary of the relevant replicaSet, I get 14603.
Is there any way that I could sync? or is there a way to use mongoimport targeting a particular shard??
(Aside: You should generally have 3 nodes in a replica set rather than 2.)
When you enable sharding on a database you can specify the primary shard. Unsharded collections will be stored on that shard. So, you can define one database per shard with each configured to have a distinct shard as the primary shard.
Alternatively if you set up zones you can specify which values of shard keys are to be stored on each shard. Then by inserting appropriate values you'd have the data stored on the shards you want.
You should be performing all operations on your sharded cluster through one of the mongos nodes, not like you have done writing directly to shard mongods.
I have a shard mongo cluster(shard node has no replica set), and some applications are using it, I want to real-time migrations to a replica set mongo cluster. Does anyone know how to do it? Thanks
We have a mongoDB replica set which has 3 nodes;
Primary
Secondary
Arbiter
Somehow our replica set has ended up with 1 & 2 both being set as secondary members. I'm not sure how this has happened (we have had a server migration which one of the nodes runs on, but only one).
Anyway, I've been trying to re-elect a new primary for the replica set following the guide here
I'm unable to just use
rs.reconfig(cfg)
as it will only work if directed at the primary (which I don't have).
Using the force parameter
rs.reconfig(cfg, { force: true})
would appear to work but then when I requery the status of the replica set, both servers are still only showing as Secondary.
Why hasn't the force reconfig worked? Currently the database is locked out whatever I try.
1.Convert all nodes to standalone.
Stop mongod deamon and edit /etc/mongod.conf to comment replSet option.
Start mongod deamon.
2.Use mongodump to backup data for all nodes.
Reference from mongo docs:
https://docs.mongodb.com/manual/reference/program/mongodump/
3.Log into each node, and drop local database.
Doing this will delete replica set config on the node.
Or you can just delete a record in collection system.replset in local db, like it said here:
https://stackoverflow.com/a/31745150/4242454
4.Start all nodes with replSet option.
5.On the previous data node (not arbiter), initialize a new replica set.
6.Finally, reconfig replica set with rs.reconfig.
Does anybody knows of a way to add a replica set to a mongo instance which hasn't been started with -replSet and without restarting it ? In other words is it possible to create a replica set and add already running instances of mongodb ?
You need to start mongod with a --replSet parameter (or replSet config file option) in order to use replication. There are replication background tasks and other server internals that are not enabled in standalone mode.
There is no method (as at MongoDB 2.2.0) to change the role of a running mongod instance from standalone to replica set mode (or vice-versa).
In other words is it possible to create a replica set and add already running instances of mongodb ?
As noted, you would need to restart those instances with the replSet parameter.
You can, however, add additional members to a running replica set without downtime.
For more information see the MongoDB manual: Add Members to a Replica Set.