Dont know if anyone gives a damn but if you guys are stoned like me atm then you can watch pretty much all of the new series on instaflixxer. Have been binge watching with my brother for the last few days =)
I just found this video, i couldve saved hours from the things i did which is only 12 minutes in this videos creating a replica set with 3 instances of mongdb. Wow! im gonna watch the whole series now. Thank you so much!
what would be connecting string if we wanted to connect to this same replica set using the mongsqld commands i used './mongosqld --mongo-uri "mongodb://mongo-0.mongo:27017,mongo-1.mongo:27017,mongo-2.mongo:27017/?replicaSet=rs0&readPreference=secondary"' and i am getting the error current topology: Type: ReplicaSetNoPrimary, unable to discover
Hey Bro You forgot an experiment in this Lab mongodb replica set with 3 Nodes will be very good but if 1 of 3 Nodes die then there is no problem. But if 2 out of 3 nodes, an even number, die, you know the consequences. Without a Primary Node, what will you do now? And the next thing is that the Primary's job is divided among the Slave Nodes. But the main responsibility is still the Primary Node. Suppose at some point your Primary Node is Full Disk and your system resources cannot be scaled vertically, what do you plan to do with your MongoDB Cluster?. Please give me your answer as soon as possible. Thanks!!!
Thanks for very helpful video. I have one confusion When you connected to first mongo instance and did rs.initiate() In mongo prompt appears that is secondary but after you rs.status() it shows that node is primary?
thank you for this very explanatory tutorial. I have a question: can we just use 2 machines for replication or 3 machines is the minimum? I can't find anything about it in the documentation Thanks.
Hi Chatti, thanks for watching. I would always advise to go with a minimum of 3 node replicaset with all of them containing the data. If a node goes down, then you will only be left with one node if you had just 2 node replicaset. If you don't want to replicate the data on 3 nodes, you can just have 2 nodes that contains data and an arbiter node that only takes part in election and doesn't hold the actual data. docs.mongodb.com/manual/core/replica-set-architecture-three-members/
Hi Venkat, Thanks for nice video. I did mongodb replica set by seeing your vidoe, however noticed secondary node asks to run rs.slaveOk() command before run any command when i connects to its(secondary node) mongo shell. Could you please let me know is this expected beheaviour.
Hi, thanks for watching. This below video will give you some idea. ruclips.net/video/SY_9zwb29LA/видео.html Basically you bring up a replicaset with authentication enabled on all nodes either through a config file or through a command line option "--auth" and then set up users/roles on primary which will get replicated.
Thanks for the awesome video Venkat :) I have a small question. -> I am setting up 3 mongo docker containers in the same centos machine. but I am not able to change the default port. I don't want to use docker-compose file, do u have any solution for Dockerfile? where I can change the default MongoDB port? mongodb0 docker run --hostname mongodb0 -d -p 25000:27017 -v /data/mongodb0:/data/db/ --network='database' --name mongodb0 mongo:latest --replSet "rs0" mongodb1 docker run --hostname mongodb1 -d -p 26000:27017 -v /data/mongodb1:/data/db/ --network='database' --name mongodb1 mongo:latest --replSet "rs0" mongodb2 docker run --hostname mongodb2 -d -p 27000:27017 -v /data/mongodb2:/data/db/ --network='database' --name mongodb2 mongo:latest --replSet "rs0"
Hi Abhishek, thanks for watching. Your docker run commands seems to right. Since you are running all these containers on the same host machine, you will have to bind them to different ports like what you did. I am not entirely sure what you are after?
Why I got "writeConcern is not allowed within a multi-statement transaction" when trying the "multi-document transaction". I ran in on primary node. Please help!
I have a Question. How can we configure authentication for client connections on a replica set? One other thing, have been following your new AWS series and I am really learning a lot.
Hi Varun, thanks for watching and for your interest in this series. I have done a video on configuring authentication in Mongo DB which you can watch it at ruclips.net/video/SY_9zwb29LA/видео.html Thanks.
There does not seem to be mongo services deployed on docker swarm , just separate mongodb containers on different hosts. Mapping in /etc/hosts also seems counter productive , because it implies you always want mongo0 on hostA , mongo1 on hostB and mongo2 on hostC. That is not how services deployed on docker swarm work - mongo0 , mongo1 and mongo2 as services could be deployed randomly on hostA or hostB or hostC.
Hi Nirmal, thanks for watching. You can do that. In fact you can set up a replicaset with nodes running anywhere. But you have to bear in mind the latency and other stuff. To be able to setup a replicaset, all you need is mongo instances running. It can run anywhere. You have to take into account firewall, latency and security. If the nodes can talk to each other on port 27017, then you can hook them up.
Hi, using the local server with three instances without issue, but if have three separate servers, facing node not found error. Are you able to advice? Thank you.
thanks for your amazing videos. Quick question . Can I have my own cluster of mongodb ? , If yes why I need to pay amazong and other companies to do that . I am thinking that I'm missing something very important. For example I'm never going to use docker to run my relational database . Can you please help me to understand it in a better way
Hi venkat I am from India..the explanation was really great but I have one doubt: I have converted my standalone to replica sets in windows lastday but today after restarting my system 1.I am unable to Rerun my replica sets(getting this error: connect failed to replica set myReplicaSet/localhost:27017,localhost:27027,localhost:27037). 2.when I run my primary node(27017)..it is telling me that " "errmsg" : "This node was not started with the replSet option" when i typed rs.status() and also giving throwing as "Document(s) exist in 'system.replset', but started without --replSet." PLEASE HELP ME VENKAT
@@justmeandopensource When I installed MongoDb in Windows it showed showed as Standalone cluster(mongo compass UI) hosted with port number: 27017 then..in shell I used the below command to make it as replica set. mongod --dbpath "C:\Program Files\MongoDB\Server\4.4\data" --logpath "C:\Program Files\MongoDB\Server\4.4\log\mongod.log" --port 27017 --storageEngine=wiredTiger --journal --replSet myReplicaSet
At 10:46 when you execute the cat command, I cannot see the IP Address of my 3 mongodb's, and all my 3 machines are running, can you tell how can I add this data?
Thanks for the video Venkat. But something wrong when i have connect to replica Sets like this: "client = MongoClient("mongodb://mongodb0:27017,mongodb1:27017,mongodb2:27017/?replicaSet=rs0")" and error below: "ServerSelectionTimeoutError errno 11001 getaddrinfo failed python" seem the Primary did not connect to Secondary for reading data. Could you help?
Is there anyway of doing a multi master set-up in mongodb like mysql. I have a multi-cloud replica setup on digitalocean and linode where my primary is on digitalocean . I would like to have one-more master on linode so that in case the communication is cut between the two environments I would still want my application on linode to perform write operations.
HI Varun, thanks for watching. The master node in MongoDB cluster is called Primary. No master/slave concept. It is Primary/Secondary. By design, you can't have two primaries in a cluster. What you can do is spread your replicaset across different providers DO and Linode. If one of the provider has problem, then a secondary from another provider can take the primary role.
I have to execute rs.slaveOk() everytime on the secondary nodes to read databases. How can I avoid executing this everytime when connecting to the secondary.
Hi Varun, I don't think there is a way to set the rs.slaveOk() in a permanent way. rs.slaveOk() is set per connection session. This is needed only when you are directly connecting to a secondary member of the replicaset. Why do you want to connect directly to a secondary member. You can still connect to the full replicaset and direct the reads to secondary members by passing readPreference option in the connection string. For example, if your replicaset name is myrepl and your hosts are mongo-0, mongo-1 & mongo-2, then you can use below connection string. $ mongo mongodb://mongo-0:27017,mongo-1:27017,mongo-2:27017/admin?replicaSet=myrepl&readPreference=secondary This will do any reads from secondary and writes will happen on primary. Cheers.
lets say I make some changes in primary (create database test-db, and db.tester.insert() some values) Without doing rs.slaveOk() how can I simply view the changes in secondary? So when I update primary, I don't want to update the values. But how can I do a .find() in my secondary servers without explicitly entering `rs.slaveOk()`?
@@david19993 The replica set will take care of the replication between its members. May I ask you why you want to connect directly to a secondary member? If you want to directly connect to a secondary member, then there is no way other than running rs.slaveOk() to interact with the database.
Hi Abhimanyu, thanks for watching. Not just Mongodb cluster, generally in any cluster you will have odd number of nodes. In mongodb replicaset, the minimum nodes recommended is 3. You can however run just two nodes with one primary and one secondary. As long as the master node is running fine, you won't see any problem. But if master dies, the only secondary node will have to take the primary role but it might not have catched up with the master. So loss of data might happen. If there are two secondaries, there will be election to find out which can become the primary.
Hey hi, thanks for the such a great video. I have question, i have 3 slave and 1 master node mongodb replicaset in kubenates. I used the replicaset name to connect inside the cluster as you shown in video. Now i want to connect outside the cluster, how can i do that. Thank in advance.
Hi Rajesh, thanks for watching this video. I actually have this in my list. The video will be about deploying mongodb as a statefulset inside a Kubernetes cluster. Only if you are deploying mongodb replicaset outside the k8s cluster you will have to think about traditional architecture and accessing the replicaset uri, by passing all the replicas in the uri. Whereas if you are deploying inside a kubernetes cluster, you can just deploy them as a normal kubernetes replicaset. And expose the deployment as a LoadBalancer or nodeport service. I haven't tried any of these. But will soon record a video for it. Thanks.
Thanks for your reply, When i exposed as LoadBlaancer or Node Port, it will switch b/w primary and secondary(works in round robbin .).My question is how can handle in the application. Should i use Drivers or any think else. Please helm me here. Thanks in advance.
@@RAJESHNAYAK-wg5li You don't deploy them as a mongodb replicaset with primary and secondary inside the cluster. Its like any other deployment with number of replicas. So all of them are same and no primary/secondary concept. Thanks.
Thank you so much for this tutorial. It's great! I have a problem, it would be great if you can help! (i've searched a lot online, but no luck) i did the exact replicaset over 2 servers: Server A in docker: db1, db2 & Server B in docker: db3 if db1 was primary & i stop the container db1, db2=> will be set to primary, and everything will keep on working fine same story for db2 however if i stop db1 and db2 (or if i shutdown the whole server of db1 and db2), db3 is staying forever secondary! any idea?
Great video, quick question. I used docker and not lxc. If i put all three "mongoDb servers" on three dockers, it works fine. If I use two dockers, and my local machine, it does not work and it says network is unreachable. Any idea why this might be the case? I've exposed ports, and mapped them correct `docker run -p 27017:27017` A bit confused as to why the dockers can interact with each other, but my host machine cannot interact with any of the containers?
@@justmeandopensource yes! rs.initiate() doesn't work. Then I put my "host machine mongoDb" on to a docker as well, and works with 3 dockers beautifully.
@@david19993 Are you defining a separate network for your docker containers in your docker-compose file? I haven't actually tried that setup to be honest.
@@justmeandopensource well, my dockers have `172.17.0.*` as IPs, and so I just use my host machines IP address. It may be something to do with my firewall. Anyway, this is not a question about mongoDb but more docker. Thanks for the video, the response, and just being a great experience! Subscribed!
Dear, How to use/set `/etc/hosts` for difference ip? Does you do this on your local machine? 10.92.25.103 mongo0 10.92.250.227 mongo1 10.92.250.62 mongo2 What difference with 3 docker container in difference port? ports: - 40001:27017 ports: - 40002:27017 ports: - 40003:27017
Hi Theara, Thanks for watching this video. Are you running these three mongodb containers on the same machine or on a separate virtual machines? If you want to run all 3 mongo containers on the same machine using docker-compose, you need to map them to different ports on your host machine. If you are running each of the mongo containers in its own virtual machine, then you can just run them on 27017 the default port. Thanks.
Hi Theara, I just responded to the github issue. Please use this RUclips chat section for all your queries. This will help other viewers as well. Thanks.
what is the difference between rs.initiate() vs rs.initiate( { _id : "rs0", members: [ { _id: 0, host: "localhost:27017" }, { _id: 1, host: "localhost:27018" }, { _id: 2, host: "localhost:27019" } ] }) what is the condition of both cases.
Hi Atul, thanks for watching. rs.initiate() requires replicaset configuration. You either add the configuration beforehand and run rs.initiate() or pass the replicaset configuration within this method.
@@justmeandopensource Error: Failed container creation: Create LXC container: LXD doesn't have a uid/gid allocation. In this mode, only privileged containers are supported
Hi Theara, there is no specific answer to this question. It depends on a lot of factors like - how many shards you need - how big you expect your database to grow - what OS you are going to use - whether you are going to run mongo as docker containers or install directly on droplets For production use case, consider reading the below article www.mongodb.com/blog/post/capacity-planning-and-hardware-provisioning-mongodb-ten-minutes For just learning purpose, you can do with just one Digital Ocean droplet and run as many mongodb containers as you want in as many shards as you like. I have done couple videos on sharding, hope you watched them as well. If not here are the links. ruclips.net/video/7Lp6R4CmuKE/видео.html ruclips.net/video/LGERGvEaPW0/видео.html ruclips.net/video/Rwg26U0Zs1o/видео.html Thanks
Hi James, What do you mean by read replicas? You can just add additional secondary members to your replicaset if your read traffic is increasing. All your reads will happen on secondary members when you pass the "readPreference=secondary" to the mongodb connection string when connecting. Cheers.
Hi bro great video i followed the steps and I created the three mongodb instance but when i am using read preference its not connecting via spring boot can you advice getting this error" No server chosen by com.mongodb.client.internal.MongoClientDelegate"
Hi Leo, thanks for watching. Can you check if you can access the replicaset from a mongo shell first? And what is the connection string you are using from your spring boot application?
@@justmeandopensource I can connect to replica set without read preference but when read preference is given its not going to shell ,but replication is happening when i create some collections in primary node
Hi Atul, thanks for watching. There are different ways to add members to a replicaset. What I have shown in this video is one method. If you want to add individual members later, you can follow your approach. Cheers.
Hello.....I am back again with one question... So, I deployed a replica set of MongoDB and I have three machines (Mongo1:127.0.0.1(Primary), Mongo2:127.0.0.2(sec), Mongo3:127.0.0.3(sec)). Now we know if the mongo1(primary) will die then one of the secondary will be primary and when it will b back it will be one of the secondary nodes. Suppose I am using the mongo1 IP in all my scripts and application which is 127.0.0.1 and as we know all read and write are on primary so suppose if it will die then I have to go and change the primary IP in all my script. How I can handle this problem.
Hi Abhi, thanks for watching. Whenever you are connecting to a replicaset from a mongo shell or from any client application, you will have to use the replicaset uri and not the ip address of a single mongo node. In your case, you will have to replicaset uri like "mongodb://mongo1:27017,mongo2:27017,mongo3:27017/database?replicaSet=replicaset-name". By using this URI format, the connection will be made to any available mongo node in the cluster. Cheers.
@@abhimanyukumar4185 By using that connection string, it will connect to any available instance in the replicaset. In a replicaset if the master node goes down, one of the secondaries will become the primary. You will have to implement some form of monitoring to get alerted when a node goes down and bring it as soon as possible.
@@justmeandopensource I got that. Suppose mongo1 is master and it goes down and mongo3 will be next master so it will go to that one. If i am getting it right.
hi Sir, I am getting some different message of the command rs.status() rs.status() { "ok" : 0, "errmsg" : "not running with --replSet", "code" : 76, "codeName" : "NoReplicationEnabled" } What is the meaning of this ?
Hi Theara, mongos router is very light-weight and acts as an interface/gateway to your shards. From your applications you connect to one of the mongos router and do the db operations. Mongos will read/write data to the appropriate shard. Config servers are deployed as replicaset which stores information about the shards in your cluster. mongos router retrieves these information from config servers and uses it to find the data in the shard. You don't need to deploy mongos as a replicaset. You can run as many mongos router as you want on any machine. Typically a mongos router will be configured on the server where your client application reside. For more information you can check the official mongos documentation in the below link. docs.mongodb.com/manual/core/sharded-cluster-query-router/ Thanks.
Yes. It can be deployed anywhere on any machine, preferably on the server itself where your client application is running. Once you create the mongos router anywhere, you connect to it and add the shards that you want. Thanks.
Thanks for your video. I base on Mac. I tried to run 3 docker container that difference by port (Not 3 host machine). I have problem with mongo connection ``` mongo 'mongodb://mongo1:27018,mongo2:27019:27020/?replicaSet=rs0 --- no primary found in replicaset or invalid replica set name ``` cat /etc/hosts ``` 127.0.0.1 mongo1 127.0.0.1 mongo2 127.0.0.1 mongo3 ```
Hi Theera, Thanks for watching this video. I am not sure how you are starting the 3 docker containers for mongodb. Basically you run the same docker mongodb container in the default port 27017 but map to different host port on your mac. And don't have 127.0.0.1 entries in your /etc/hosts file. That will cause other problems. I am not sure if you have watched my other mongodb videos around sharding concept. I have docker-compose.yaml file ready for you to use. Check the below docker-compose file. github.com/justmeandopensource/learn-mongodb/blob/master/sharding/shard1/docker-compose.yaml Download it and run "docker-compose up -d". It will start 3 mongodb containers. All these containers use the default port 27017 but they are mapped to host machine on 50001, 50002 and 50003. Now you need to connect to one of the instance and initialize the replicaset. Check the below doc under shard1 servers. github.com/justmeandopensource/learn-mongodb/blob/master/sharding/00-setup-sharding-doc.md Now you can connect to the replicaset with the ip address of your mac machine. For example, if you mac's ip is 192.168.1.5, you can use the below command to connect. mongo mongodb://192.168.1.5:50001,192.168.1.5:50002,192.168.1.5:50003/?replicaSet=rs0 Use the replicaset name in the above command as what you defined while initializing the replicaset. Hope this makes sense. Thanks
@@justmeandopensource Thanks for your quick reply. Yes I tried with `docker-composer.yml`, and mapped to host machine on difference port. Ex: 27018:27017, 27019:27017, 27020:27017 But don't use `--shardsvr`. I don't understand about `--shardsvr` option?. Oh I connect to mongo with `localhost:27018,localhost:27019, localhost:27020/?.....` I will try with your doc...
At 14:50 when you run this command I am getting this error - MongoNetworkError: getaddrinfo ENOTFOUND mongodb0 Can you help me in resolving this issue?
Addicted to Venket's Videos... Slideless practical way of teaching. Thank you.
Hi Srini, thats great to hear and many thanks for watching. Cheers.
Dont know if anyone gives a damn but if you guys are stoned like me atm then you can watch pretty much all of the new series on instaflixxer. Have been binge watching with my brother for the last few days =)
@Lorenzo Magnus definitely, been watching on InstaFlixxer for years myself =)
@Lorenzo Magnus Definitely, have been watching on instaflixxer for since december myself :)
I just found this video, i couldve saved hours from the things i did which is only 12 minutes in this videos creating a replica set with 3 instances of mongdb. Wow! im gonna watch the whole series now. Thank you so much!
Hi Jeff, glad to hear that. Thanks for watching.
the greatest video about MongoDB i ever watch
Thanks for watching.
Great video thanks for sharing! Do you need to have a minimum of three servers to configure a replica set? Or can I set one up with only two?
Hi Mike, thanks for watching. Minimum would be a 3 node replicaset.
@@justmeandopensource Good to know.
No worries.
Excellent..do you have any video to show cross region replication for mongodb 3 pods?
I am afraid not. THanks for watching.
what would be connecting string if we wanted to connect to this same replica set using the mongsqld commands
i used './mongosqld --mongo-uri "mongodb://mongo-0.mongo:27017,mongo-1.mongo:27017,mongo-2.mongo:27017/?replicaSet=rs0&readPreference=secondary"'
and i am getting the error current topology: Type: ReplicaSetNoPrimary, unable to discover
Great demonstration. Thank you for the video!
Hi Xuan, Thanks for watching.
Hey Bro
You forgot an experiment in this Lab
mongodb replica set with 3 Nodes will be very good but if 1 of 3 Nodes die then there is no problem. But if 2 out of 3 nodes, an even number, die, you know the consequences. Without a Primary Node, what will you do now?
And the next thing is that the Primary's job is divided among the Slave Nodes. But the main responsibility is still the Primary Node. Suppose at some point your Primary Node is Full Disk and your system resources cannot be scaled vertically, what do you plan to do with your MongoDB Cluster?.
Please give me your answer as soon as possible. Thanks!!!
Thank you bro, got the clear idea on mongodb replica set.👍
Hi Venkatesh, thanks for watching.
Thanks for very helpful video. I have one confusion When you connected to first mongo instance and did rs.initiate() In mongo prompt appears that is secondary but after you rs.status() it shows that node is primary?
Great job Venkat, this is really helpful!
Hi Achyuth, thanks for watching.
thank you for this very explanatory tutorial.
I have a question: can we just use 2 machines for replication or 3 machines is the minimum?
I can't find anything about it in the documentation
Thanks.
Hi Chatti, thanks for watching. I would always advise to go with a minimum of 3 node replicaset with all of them containing the data. If a node goes down, then you will only be left with one node if you had just 2 node replicaset. If you don't want to replicate the data on 3 nodes, you can just have 2 nodes that contains data and an arbiter node that only takes part in election and doesn't hold the actual data.
docs.mongodb.com/manual/core/replica-set-architecture-three-members/
Hi Venkat,
Thanks for nice video. I did mongodb replica set by seeing your vidoe, however noticed secondary node asks to run rs.slaveOk() command before run any command when i connects to its(secondary node) mongo shell. Could you please let me know is this expected beheaviour.
Hi Sunil, thats expected when you connect directly to a secondary node instead of a replica set connection uri.
Is there any gui tool to setup replication rather than running through manual procedures?
Hi very good tutorial thanks. A question how to enable authentication into a replicaset? Only on primary and how using a docker? Thanks.
Hi, thanks for watching.
This below video will give you some idea.
ruclips.net/video/SY_9zwb29LA/видео.html
Basically you bring up a replicaset with authentication enabled on all nodes either through a config file or through a command line option "--auth" and then set up users/roles on primary which will get replicated.
@@justmeandopensource Amazing thanks :)
@@giovanni.piedimonte No worries.
Nice video. @Just me and Opensource can you show how you set-up docker
I love your videos. Great quality work and very useful and practical. Thanks!
Hi Jay, thanks for watching.
As always - phenomenal video Venkat!! You're the best buddy :)
Hi Leonardo, many thanks for your comment.
Thanks for the awesome video Venkat :)
I have a small question. -> I am setting up 3 mongo docker containers in the same centos machine. but I am not able to change the default port. I don't want to use docker-compose file, do u have any solution for Dockerfile? where I can change the default MongoDB port?
mongodb0
docker run --hostname mongodb0 -d -p 25000:27017 -v /data/mongodb0:/data/db/ --network='database' --name mongodb0 mongo:latest --replSet "rs0"
mongodb1
docker run --hostname mongodb1 -d -p 26000:27017 -v /data/mongodb1:/data/db/ --network='database' --name mongodb1 mongo:latest --replSet "rs0"
mongodb2
docker run --hostname mongodb2 -d -p 27000:27017 -v /data/mongodb2:/data/db/ --network='database' --name mongodb2 mongo:latest --replSet "rs0"
Hi Abhishek, thanks for watching.
Your docker run commands seems to right. Since you are running all these containers on the same host machine, you will have to bind them to different ports like what you did. I am not entirely sure what you are after?
Wonderful, appriciate the efforts to help
Thanks for watching.
Why I got "writeConcern is not allowed within a multi-statement transaction" when trying the "multi-document transaction". I ran in on primary node. Please help!
I have a Question. How can we configure authentication for client connections on a replica set? One other thing, have been following your new AWS series and I am really learning a lot.
Hi Varun, thanks for watching and for your interest in this series. I have done a video on configuring authentication in Mongo DB which you can watch it at
ruclips.net/video/SY_9zwb29LA/видео.html
Thanks.
Do you recommed to run mongodb node vms in replica set to close proximities to each other when deploying vm in public cloud?
Hi thanks for watching. I would run them each in its own availability zone.
Do we have to install docker on each machine (mongodb0...)
Great explanation .
Hi Manoj, thanks for watching.
There does not seem to be mongo services deployed on docker swarm , just separate mongodb containers on different hosts. Mapping in /etc/hosts also seems counter productive , because it implies you always want mongo0 on hostA , mongo1 on hostB and mongo2 on hostC. That is not how services deployed on docker swarm work - mongo0 , mongo1 and mongo2 as services could be deployed randomly on hostA or hostB or hostC.
Hello, I had a question that can we set up sync or replication between my on-prem MongoDB server and my azure VM MongoDB server.
Hi Nirmal, thanks for watching.
You can do that. In fact you can set up a replicaset with nodes running anywhere. But you have to bear in mind the latency and other stuff.
To be able to setup a replicaset, all you need is mongo instances running. It can run anywhere. You have to take into account firewall, latency and security.
If the nodes can talk to each other on port 27017, then you can hook them up.
@@justmeandopensource Thank you very much for your response.
@@nimaiahluwalia5678 You are welcome.
you are such a blessing. Keep up the good work Venkat
Hi Ernest, many thanks for watching this video and taking time to comment/appreciate. Cheers.
The appreciation is yours Venkat for the great work you are doing to share knowledge.
@@ernestledo341 Kind of you. Thanks.
Excellent video. Very in depth.
Thanks for watching.
17:39 show dbs run into an error. now it works. Ok bro nice but what have you changed, I'm having the same issue.. thanks
Awesome!
Thanks for watching. Cheers.
Hi, using the local server with three instances without issue, but if have three separate servers, facing node not found error. Are you able to advice? Thank you.
thanks for your amazing videos. Quick question . Can I have my own cluster of mongodb ? , If yes why I need to pay amazong and other companies to do that . I am thinking that I'm missing something very important. For example I'm never going to use docker to run my relational database . Can you please help me to understand it in a better way
Hi Venkat, these mongodb series are very very useful and clearly explained many things. Can you please make some videos on Mysql DB. Thanks.
Hi venkat I am from India..the explanation was really great but I have one doubt: I have converted my standalone to replica sets in windows lastday but today after restarting my system
1.I am unable to Rerun my replica sets(getting this error: connect failed to replica set myReplicaSet/localhost:27017,localhost:27027,localhost:27037).
2.when I run my primary node(27017)..it is telling me that " "errmsg" : "This node was not started with the replSet option" when i typed rs.status() and also giving throwing as "Document(s) exist in 'system.replset', but started without --replSet."
PLEASE HELP ME VENKAT
Hi, when you say you converted standalone to replicaset, how exactly you did it?
@@justmeandopensource When I installed MongoDb in Windows it showed showed as Standalone cluster(mongo compass UI) hosted with port number: 27017 then..in shell I used the below command to make it as replica set.
mongod --dbpath "C:\Program Files\MongoDB\Server\4.4\data" --logpath "C:\Program Files\MongoDB\Server\4.4\log\mongod.log" --port 27017 --storageEngine=wiredTiger --journal --replSet myReplicaSet
. bos i subscribed to your channel , now already had another one to depend at times like this . got ur back
Thanks for watching and subscribing. Cheers.
@@justmeandopensource . hahaha . your so much , just let me thank you for my sub, like and support :DD
@@mackynikat8833 :)
@@justmeandopensource ^^_
. forgot about it boss , do you a video about what is a seed list in mongodb ? can u send me the link ?
At 10:46 when you execute the cat command, I cannot see the IP Address of my 3 mongodb's, and all my 3 machines are running, can you tell how can I add this data?
Hi , thanks for the great tutorial. is it possible to get the docker file that you used for this deployment?
Thanks for the video Venkat.
But something wrong when i have connect to replica Sets like this: "client = MongoClient("mongodb://mongodb0:27017,mongodb1:27017,mongodb2:27017/?replicaSet=rs0")" and error below:
"ServerSelectionTimeoutError errno 11001 getaddrinfo failed python"
seem the Primary did not connect to Secondary for reading data. Could you help?
This is gold. Thank you..
Hi Burak, thanks for watching. Cheers.
Is there anyway of doing a multi master set-up in mongodb like mysql. I have a multi-cloud replica setup on digitalocean and linode where my primary is on digitalocean . I would like to have one-more master on linode so that in case the communication is cut between the two environments I would still want my application on linode to perform write operations.
HI Varun, thanks for watching. The master node in MongoDB cluster is called Primary. No master/slave concept. It is Primary/Secondary. By design, you can't have two primaries in a cluster. What you can do is spread your replicaset across different providers DO and Linode. If one of the provider has problem, then a secondary from another provider can take the primary role.
Thank you so much
Thanks for watching David.
I have to execute rs.slaveOk() everytime on the secondary nodes to read databases. How can I avoid executing this everytime when connecting to the secondary.
Hi Varun, I don't think there is a way to set the rs.slaveOk() in a permanent way. rs.slaveOk() is set per connection session. This is needed only when you are directly connecting to a secondary member of the replicaset. Why do you want to connect directly to a secondary member. You can still connect to the full replicaset and direct the reads to secondary members by passing readPreference option in the connection string.
For example, if your replicaset name is myrepl and your hosts are mongo-0, mongo-1 & mongo-2, then you can use below connection string.
$ mongo mongodb://mongo-0:27017,mongo-1:27017,mongo-2:27017/admin?replicaSet=myrepl&readPreference=secondary
This will do any reads from secondary and writes will happen on primary.
Cheers.
lets say I make some changes in primary (create database test-db, and db.tester.insert() some values) Without doing rs.slaveOk() how can I simply view the changes in secondary?
So when I update primary, I don't want to update the values. But how can I do a .find() in my secondary servers without explicitly entering `rs.slaveOk()`?
@@david19993 The replica set will take care of the replication between its members. May I ask you why you want to connect directly to a secondary member? If you want to directly connect to a secondary member, then there is no way other than running rs.slaveOk() to interact with the database.
can we just have one primary and one secondary when doing a replica? if not why? and why its necessary to have three.
Hi Abhimanyu, thanks for watching. Not just Mongodb cluster, generally in any cluster you will have odd number of nodes. In mongodb replicaset, the minimum nodes recommended is 3. You can however run just two nodes with one primary and one secondary. As long as the master node is running fine, you won't see any problem. But if master dies, the only secondary node will have to take the primary role but it might not have catched up with the master. So loss of data might happen. If there are two secondaries, there will be election to find out which can become the primary.
wonderful
Hi John, thanks for watching this video.
Hey hi, thanks for the such a great video. I have question, i have 3 slave and 1 master node mongodb replicaset in kubenates. I used the replicaset name to connect inside the cluster as you shown in video. Now i want to connect outside the cluster, how can i do that. Thank in advance.
Hi Rajesh, thanks for watching this video. I actually have this in my list. The video will be about deploying mongodb as a statefulset inside a Kubernetes cluster.
Only if you are deploying mongodb replicaset outside the k8s cluster you will have to think about traditional architecture and accessing the replicaset uri, by passing all the replicas in the uri.
Whereas if you are deploying inside a kubernetes cluster, you can just deploy them as a normal kubernetes replicaset. And expose the deployment as a LoadBalancer or nodeport service.
I haven't tried any of these. But will soon record a video for it. Thanks.
Thanks for your reply,
When i exposed as LoadBlaancer or Node Port, it will switch b/w primary and secondary(works in round robbin .).My question is how can handle in the application. Should i use Drivers or any think else. Please helm me here. Thanks in advance.
@@RAJESHNAYAK-wg5li You don't deploy them as a mongodb replicaset with primary and secondary inside the cluster. Its like any other deployment with number of replicas. So all of them are same and no primary/secondary concept. Thanks.
awesome thanks.
You are welcome.
Nice series bro. I've learned and enjoying a lot. Keep it up!
New subscriber here!
Hi Rommel, many thanks for watching and subscribing. Cheers.
Thank you so much for this tutorial. It's great!
I have a problem, it would be great if you can help! (i've searched a lot online, but no luck)
i did the exact replicaset over 2 servers: Server A in docker: db1, db2 & Server B in docker: db3
if db1 was primary & i stop the container db1, db2=> will be set to primary, and everything will keep on working fine
same story for db2
however if i stop db1 and db2 (or if i shutdown the whole server of db1 and db2), db3 is staying forever secondary!
any idea?
Very helpful video. Thanks!
Hi Oleksandr, thanks for watching.
thanks , really clever explanation!
Hi Djosef, thanks for watching.
Great video, quick question. I used docker and not lxc. If i put all three "mongoDb servers" on three dockers, it works fine. If I use two dockers, and my local machine, it does not work and it says network is unreachable. Any idea why this might be the case? I've exposed ports, and mapped them correct `docker run -p 27017:27017` A bit confused as to why the dockers can interact with each other, but my host machine cannot interact with any of the containers?
At what point it says network is unreachable? During rs.initiate() stage?
@@justmeandopensource yes! rs.initiate() doesn't work. Then I put my "host machine mongoDb" on to a docker as well, and works with 3 dockers beautifully.
@@david19993 Are you defining a separate network for your docker containers in your docker-compose file? I haven't actually tried that setup to be honest.
@@justmeandopensource well, my dockers have `172.17.0.*` as IPs, and so I just use my host machines IP address. It may be something to do with my firewall. Anyway, this is not a question about mongoDb but more docker. Thanks for the video, the response, and just being a great experience! Subscribed!
@@david19993 Thanks for subscribing. Much appreciated.
Awesome Thank's
Thanks for watching.
Dear,
How to use/set `/etc/hosts` for difference ip?
Does you do this on your local machine?
10.92.25.103 mongo0
10.92.250.227 mongo1
10.92.250.62 mongo2
What difference with 3 docker container in difference port?
ports:
- 40001:27017
ports:
- 40002:27017
ports:
- 40003:27017
Hi Theara,
Thanks for watching this video.
Are you running these three mongodb containers on the same machine or on a separate virtual machines?
If you want to run all 3 mongo containers on the same machine using docker-compose, you need to map them to different ports on your host machine. If you are running each of the mongo containers in its own virtual machine, then you can just run them on 27017 the default port.
Thanks.
@@justmeandopensource
Thanks, Very clear
@@justmeandopensource
Excuse me, I have some issue on your github repo.
Could you check?
Hi Theara, I just responded to the github issue. Please use this RUclips chat section for all your queries. This will help other viewers as well. Thanks.
thankkkkkkkkssss you are literally a life saver
Thanks for watching.
very nice explanation...can you make videos on cassandra
Hi Sameer, thanks for watching this video. I don't know much about Cassandra. At the moment, I am focusing on Kubernetes and AWS series. Cheers.
what is the difference between
rs.initiate()
vs
rs.initiate( {
_id : "rs0",
members: [
{ _id: 0, host: "localhost:27017" },
{ _id: 1, host: "localhost:27018" },
{ _id: 2, host: "localhost:27019" }
]
})
what is the condition of both cases.
Hi Atul, thanks for watching.
rs.initiate() requires replicaset configuration. You either add the configuration beforehand and run rs.initiate() or pass the replicaset configuration within this method.
Very good video for beginners . The demo is excellent
Hi Venkat, can you provide me a link for how to create lxc container, which you have shown in this video.
Hi, thanks for watching. I have a separate series covering LXC/LXD concepts. If you are interested.
ruclips.net/video/CWmkSj_B-wo/видео.html
@@justmeandopensource it's getting error when I give cmd lxc launch ubuntu:16.04
@@aponiartest2802 What error do you get?
@@justmeandopensource Error: Failed container creation: Create LXC container: LXD doesn't have a uid/gid allocation. In this mode, only privileged containers are supported
VERI NICE STUFF ,TNKS SIR.
Hi Sushil, thanks for watching. Cheers.
Can you please show how to enable security in replica sets?
Hi bro thank you for this very explanatory . how to bind multiple ip address
nice Vidéo very helpfull
Hi, thanks for watching.
Could advise number of `DigitalOcean droplets` for Mongo Sharding?
- Number of droplets
- Droplets size
- ....
Hi Theara, there is no specific answer to this question. It depends on a lot of factors like
- how many shards you need
- how big you expect your database to grow
- what OS you are going to use
- whether you are going to run mongo as docker containers or install directly on droplets
For production use case, consider reading the below article
www.mongodb.com/blog/post/capacity-planning-and-hardware-provisioning-mongodb-ten-minutes
For just learning purpose, you can do with just one Digital Ocean droplet and run as many mongodb containers as you want in as many shards as you like.
I have done couple videos on sharding, hope you watched them as well. If not here are the links.
ruclips.net/video/7Lp6R4CmuKE/видео.html
ruclips.net/video/LGERGvEaPW0/видео.html
ruclips.net/video/Rwg26U0Zs1o/видео.html
Thanks
@@justmeandopensource
thanks
You are welcome.
@@justmeandopensource
I will try with 2 or 3 droplets.
Yeah. that sounds good.
Thank you from Russia))
Many thanks for watching.
Hello, how to create read replicas in mongodb in AWS?
Hi James, What do you mean by read replicas? You can just add additional secondary members to your replicaset if your read traffic is increasing. All your reads will happen on secondary members when you pass the "readPreference=secondary" to the mongodb connection string when connecting. Cheers.
Hi bro great video i followed the steps and I created the three mongodb instance but when i am using read preference its not connecting via spring boot can you advice getting this error" No server chosen by com.mongodb.client.internal.MongoClientDelegate"
Hi Leo, thanks for watching. Can you check if you can access the replicaset from a mongo shell first? And what is the connection string you are using from your spring boot application?
@@justmeandopensource I can connect to replica set without read preference but when read preference is given its not going to shell ,but replication is happening when i create some collections in primary node
@@leothomas9080 Okay. Can you share your connection string? I don't have any experience in Spring Boot.
@@justmeandopensource mongo mongo-admin:Phdxhhxyhsx@mongodb-server-1a:27017,mongodb-server-1b:27017,mongodb-server-1c:27017/admin?replicaSet=rs0&readPreference=secondaryPreferred
real nice stuff, thanks
Thanks for watching Richard.
Thanks a lot!
Hi Milon, thanks for watching.
thanks)
Thanks for watching.
very nice video
Hi , Thanks for watching.
why ddn't you use
rs.add("ServerB")
rs.add("ServerC")
Hi Atul, thanks for watching. There are different ways to add members to a replicaset. What I have shown in this video is one method. If you want to add individual members later, you can follow your approach. Cheers.
Hello.....I am back again with one question... So, I deployed a replica set of MongoDB and I have three machines (Mongo1:127.0.0.1(Primary), Mongo2:127.0.0.2(sec), Mongo3:127.0.0.3(sec)). Now we know if the mongo1(primary) will die then one of the secondary will be primary and when it will b back it will be one of the secondary nodes. Suppose I am using the mongo1 IP in all my scripts and application which is 127.0.0.1 and as we know all read and write are on primary so suppose if it will die then I have to go and change the primary IP in all my script. How I can handle this problem.
Hi Abhi, thanks for watching. Whenever you are connecting to a replicaset from a mongo shell or from any client application, you will have to use the replicaset uri and not the ip address of a single mongo node.
In your case, you will have to replicaset uri like "mongodb://mongo1:27017,mongo2:27017,mongo3:27017/database?replicaSet=replicaset-name".
By using this URI format, the connection will be made to any available mongo node in the cluster.
Cheers.
@@justmeandopensource one last question Does this provide it the order to failover with?
@@abhimanyukumar4185 By using that connection string, it will connect to any available instance in the replicaset. In a replicaset if the master node goes down, one of the secondaries will become the primary. You will have to implement some form of monitoring to get alerted when a node goes down and bring it as soon as possible.
@@justmeandopensource I got that. Suppose mongo1 is master and it goes down and mongo3 will be next master so it will go to that one. If i am getting it right.
@@abhimanyukumar4185 Yeah one of the other secondary will become master by holding an election.
nice video venkat..keep doing!.
Thanks for watching this video Gurdeep.
THANK YOOOOU!
No worries. You are welcome.
thanks you :D
HI Am, thanks for watching.
How to force secondry to become primery
hi Sir,
I am getting some different message of the command rs.status()
rs.status()
{
"ok" : 0,
"errmsg" : "not running with --replSet",
"code" : 76,
"codeName" : "NoReplicationEnabled"
}
What is the meaning of this ?
Please follow my steps carefully.
Could we create Mongos Router/Mongos with 2, 3.. nodes like ReplicaSet?
`version: "3"
services:
mongos:
container_name: mongos
image: mongo:4.0.6
command: mongos --configdb cfgrs/192.168.1.105:40001,192.168.1.105:40002,192.168.1.105:40003 --bind_ip 0.0.0.0 --port 27017
ports:
- 60000:27017
........
`
Hi Theara,
mongos router is very light-weight and acts as an interface/gateway to your shards. From your applications you connect to one of the mongos router and do the db operations. Mongos will read/write data to the appropriate shard. Config servers are deployed as replicaset which stores information about the shards in your cluster. mongos router retrieves these information from config servers and uses it to find the data in the shard.
You don't need to deploy mongos as a replicaset. You can run as many mongos router as you want on any machine. Typically a mongos router will be configured on the server where your client application reside.
For more information you can check the official mongos documentation in the below link.
docs.mongodb.com/manual/core/sharded-cluster-query-router/
Thanks.
@@justmeandopensource
thanks, It is not easy to understand.
I will try from you
@@justmeandopensource
It mean that we don't need to deploy `Mongo Route/Mongos` on mongo server.
We config it on `Application` side???
Yes. It can be deployed anywhere on any machine, preferably on the server itself where your client application is running. Once you create the mongos router anywhere, you connect to it and add the shards that you want.
Thanks.
@@justmeandopensource
Could We connect to config server/shard without `mongos/router`?
Thanks for your video.
I base on Mac.
I tried to run 3 docker container that difference by port (Not 3 host machine).
I have problem with mongo connection
```
mongo 'mongodb://mongo1:27018,mongo2:27019:27020/?replicaSet=rs0
---
no primary found in replicaset or invalid replica set name
```
cat /etc/hosts
```
127.0.0.1 mongo1
127.0.0.1 mongo2
127.0.0.1 mongo3
```
Hi Theera,
Thanks for watching this video.
I am not sure how you are starting the 3 docker containers for mongodb. Basically you run the same docker mongodb container in the default port 27017 but map to different host port on your mac. And don't have 127.0.0.1 entries in your /etc/hosts file. That will cause other problems.
I am not sure if you have watched my other mongodb videos around sharding concept. I have docker-compose.yaml file ready for you to use.
Check the below docker-compose file.
github.com/justmeandopensource/learn-mongodb/blob/master/sharding/shard1/docker-compose.yaml
Download it and run "docker-compose up -d".
It will start 3 mongodb containers. All these containers use the default port 27017 but they are mapped to host machine on 50001, 50002 and 50003.
Now you need to connect to one of the instance and initialize the replicaset.
Check the below doc under shard1 servers.
github.com/justmeandopensource/learn-mongodb/blob/master/sharding/00-setup-sharding-doc.md
Now you can connect to the replicaset with the ip address of your mac machine. For example, if you mac's ip is 192.168.1.5, you can use the below command to connect.
mongo mongodb://192.168.1.5:50001,192.168.1.5:50002,192.168.1.5:50003/?replicaSet=rs0
Use the replicaset name in the above command as what you defined while initializing the replicaset.
Hope this makes sense.
Thanks
@@justmeandopensource
Thanks for your quick reply.
Yes I tried with `docker-composer.yml`, and mapped to host machine on difference port.
Ex: 27018:27017, 27019:27017, 27020:27017
But don't use `--shardsvr`. I don't understand about `--shardsvr` option?.
Oh I connect to mongo with `localhost:27018,localhost:27019, localhost:27020/?.....`
I will try with your doc...
Don't use the --shardsvr option unless you are setting up a sharded cluster. Otherwise the steps should be similar. Thanks.
@@justmeandopensource
Now I work fine (no --shardsvr)
```
version: "3"
services:
mongo1:
container_name: mongo1
image: mongo:4.0.6
command: mongod --replSet rs0 --port 27017 --dbpath /data/db
ports:
- 5001:27017
volumes:
- mongo1:/data/db
mongo2:
container_name: mongo2
image: mongo:4.0.6
command: mongod --replSet rs0 --port 27017 --dbpath /data/db
ports:
- 5002:27017
volumes:
- mongo2:/data/db
mongo3:
container_name: mongo3
image: mongo:4.0.6
command: mongod --replSet rs0 --port 27017 --dbpath /data/db
ports:
- 5003:27017
volumes:
- mongo3:/data/db
volumes:
mongo1: {}
mongo2: {}
mongo3: {}
```
Config rs.initiate(config)
```
config = {
"_id": "rs0",
"members": [
{
"_id": 0,
"host": "192.168.1.12:5001"
},
{
"_id": 1,
"host": "192.168.1.12:5002"
},
{
"_id": 2,
"host": "192.168.1.12:5003",
},
],
}
```
Connection
```
mongo 'mongodb://localhost:5001,localhost:5002,localhost:5003/?replicaSet=rs0'
```
@@justmeandopensource
Excuse me, I can't fine the volume path
```
volumes:
mongo1: {}
mongo2: {}
mongo3: {}
```
How to update hosts
At 14:50 when you run this command I am getting this error - MongoNetworkError: getaddrinfo ENOTFOUND mongodb0
Can you help me in resolving this issue?
Are you still facing the same error?