Hi Mahesh,
I have just tested the example source code, and it successfully connected to a replica set called ‘foo’ to a primary node running on localhost.
Could you connect to the replica set via the Mongo Shell, run rs.status() and post the output of it ? This is to confirm that you have a replica set foo running.
Also, which MongoDB version are you running ?
You may also find these useful:
Regards,
Wan.
Hi Mahesh,
Based on the error message on the screenshot, it shows that you are not running with --replSet. This is why the rs.initiate() command failed to initiate a replica set. See Deploy a Replica Set for steps and guides on how to deploy a replica set.
I am using VS2013 for compilation and output . program compiling successfully but after running it I got the below error as output.
I would suggest to focus on getting a replica set configured properly first. As currently the issue is there is no replica set called foo running on localhost:27017.
Also, note that you need to run rs.status() with parentheses () to actually execute on mongo shell.
You may also find Replication Introduction useful.
Kind regards,
Wan.
Hi Mahesh,
You need to verify connections in both “directions”, as networking topologies and firewall configurations can prevent connectivity.
I would suggest to try to ping the guest (CentOS) from the host (Windows), and vice versa. If the pings are not successful then you would have to configure your VMware settings for the network connection.
You may also find these VMware knowledge base useful:
Or perhaps the answer for this question StackExchange: CentOS no network interface after installation in virtual box may be useful as well.
Note that this is not really related to MongoDB itself, and you may get a wider audience by posting a question on ServerFault, SuperUser or similar sites.
Kind regards,
Wan.