简体   繁体   中英

How do I connect to mongodb on MacOS after adding configurations for replica set?

I want to tail mongo collection's documents and in order to do so, I need to activate the oplog. Oplog requires some extra configuration in the mongod.conf file and these configurations are not letting mongo connected.

I tried to look into questions pertaining to tailing mongodb, setting conf file but none could address my need of connecting to mongodb after setting replciaset configs.

My conf file, location of which is /usr/local/etc/mongod.conf is:

systemLog:
  destination: file
  path: /usr/local/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /usr/local/var/mongodb
net:
  bindIp: 127.0.0.1
replSet=rs0
oplogSize=1024

I am not getting anything in logs, brew services list command also shows the following:

mongodb   started aviralsrivastava /Users/aviralsrivastava/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

Although, when rs0 is set, the started signal is yellow in color, with the last two lines commented, its green.

I expect mongodb to get connected, mongo shell to start but all I get is connection refused. If I comment the last two lines, mongo gets connected. And yes, I did restart mongodb via brew services restart mongodb each time I changed the config file.

Following is the error when I try to connect via command mongodb :

➜  etc mongo
MongoDB shell version v4.0.3
connecting to: mongodb://127.0.0.1:27017
2019-04-27T08:53:31.350+0530 E QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:257:13
@(connect):1:6
exception: connect failed

mongod --config path/to/config-file-portx --replSet rsName

connect: mongo --port xxx config:

config: 
rs.initialize();
rs.add(host:port-y);
rs.status()

connect with replica:

mongo "mongodb://host1,host2,host3/myDB?replicaSet=rsName"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM