Detail about the issue.
I have converted my MongoDB instance to a standalone ReplicaSet using the following config.
systemLog:
destination: file
path: /opt/homebrew/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /opt/homebrew/var/mongodb
net:
bindIp: 127.0.0.1
replication:
replSetName: "rs0"
security:
authorization: "enabled"
keyFile: /Users/username/mongodb.key
Using the following Mongo URI to connect to my MongoDB instance
"mongodb://username:password#127.0.0.1:27017/dbName?authSource=admin&replicaSet=rs0"
using the URI I can connect to my MongoDB through Studio3T but when I use this URI in my Node app through Mongoose it never connects, nor gives any error.
Following are the Screenshots for rs.status() output displaying details of member
member data from rs.status
Additional details.
NodeJs version: v14.19.1
Mongoose version: 6.3.2
MongoDB version: 5.0.7
Related
I am new to mongodb, this is my second day learning mongodb and trying to setup a sharded cluster.What I did is created virtual boxes of Ubuntu 18.04.1 LTS and installed mongodb version 4.2.8. after installing MongoDB on all of my VMs, I updated the mongod.conf file as follows (to configure Config Servers Replica Set, I connected to one of my VMs. I will be implementing 3 replica sets of Config servers)
net:
port: 27019
bindIP: 0.0.0.0,192.168.1.22,127.0.0.1
replication:
replSetName: rs01
sharding:
clusterRole: configsvr
after that, I restarted mongodb service using this command
sudo systemctl restart mongod
and when I try to connect to mongo shell or run this command
mongod --config /etc/mongod.conf
I get this error "Unrecognized Option: clusterRole". I am following official mongodb documentation on this link https://docs.mongodb.com/manual/tutorial/deploy-shard-cluster/
Any help would be greatly appreciated.
You are missing indentation in the yaml file. Suboptions need to be indented:
net:
port: 27019
bindIP: 0.0.0.0,192.168.1.22,127.0.0.1
replication:
replSetName: rs01
sharding:
clusterRole: configsvr
I am trying to connect to replica set in MongoDB with the following command:
client = MongoClient(
"PublicIP:27017,PublicIP:27017,PublicIP:27017,PublicIP:27017,PublicIP:27017",
replicaSet="rs0", readPreference='nearest',
localThresholdMS=500)
db = client.sampledb
# checks the connection to RS in Mongo
try:
db.command("serverStatus")
except Exception as e:
print(e)
else:
print("\n Connection established to the Replica Set!)
I have setup 5 nodes in AWS (1 master, 4 slaves) and the /etc/mongod.conf file in all nodes looks like this:
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
# network interfaces
net:
port: 27017
#bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
security:
authorization: "disabled"
#operationProfiling:
replication:
replSetName: rs0
When I try to connect from my local machine I get a timed out like this:
ip:27017: timed out,ip:27017: timed out,ip:27017: timed out,ip:27017:
timed out,ip:27017: timed out
Does anyone know why?
Starting 3.6 bindIp defaults to localhost only. So, assuming you are running 3.6 or later your configuration is not accessible from outside, since you commented out bindIp.
This post might be helpful to understand some of the nuances: https://www.mongodb.com/blog/post/enabling-ip-security-for-mongodb-36-on-ubuntu
Obviously, don't forget to make sure AWS Security Group on your instances allows Ingress connection on port 27017.
I am trying to set up a MongoDB replica set via ansible.
Therefore I am templating the following file (and it works)
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
net:
port: 27017
bindIp: 127.0.0.1,{{ inventory_hostname }}
processManagement:
timeZoneInfo: /usr/share/zoneinfo
replication:
replSetName: "{{ mongodb_replicaset_name }}"
What are the additions/modifications that I should make, so that one of the hosts becomes primary and the other two secondaries, without me havint to resort to the mongo cli?
According to the documentation (https://docs.mongodb.com/manual/tutorial/deploy-replica-set/),
Run rs.initiate() on just one and only one mongod instance for the replica set.
It appears you must connect via mongo CLI to at least one member of the replica set and initiate it. From there the voting system should kick in automatically and one of the RS becomes primary.
Here's my problem.
Our solution :
Front web connect to a cloud mongodb instances.
End-point client connect to a local mongodb instances.
People put some data throught the Front web, those data must be sync to the local instances for end-point client.
End-point client generate some data to the local's instance which must be sync to the cloud environnement.
================================
I tried to use mongo-connector to sync both way and I did sync something but everytime mongo-connector sync only half of the data randomely...
Here's my local mongodb conf :
# Where and how to store data.
storage:
dbPath: /server/mongo/data
journal:
enabled: true
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
replication:
replSetName: rs-local
Master mongodb conf:
# Where and how to store data.
storage:
dbPath: /server/mongo/data
journal:
enabled: true
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#operationProfiling:
replication:
replSetName: master-replica-01
This is the command I use for mongo-connector :
/usr/local/bin/mongo-connector -m localhost:27017 -t X.X.X.X:27017 -d mongo_doc_manager -n "db.role,db.site,db.split,db.organism,db.users,db.namespace1.namespace2.namespace3.*" --admin-username mongosu --password verysecretpassword--oplog-ts /server/mongo/data/oplog.timestamp --no-dump --enable-syslog
Everytime I dump the database then launch the mongo-connector I got some of my data but not all of it...
I thought it was an oplog problem so set the oplog to 16Gb.
Many help ask :)
Elenui
I am trying to restrict the mongodb to local ip, it is not working.
Using MongoDb 3.2 version.
Below is the configuration file for the service, which is located in "C:\Program Files\MongoDB\Server\3.2\mongod.cfg"
systemLog:
destination: file
path: c:\data\mongo.log
quiet: false
logAppend: true
storage:
dbPath: C:\data\db
directoryPerDB: true
wiredTiger:
engineConfig:
cacheSizeGB: 2
directoryForIndexes: true
net:
port: 27017
bindIp: [127.0.0.0, 10.64.87.231]
replication:
oplogSizeMB: 500
replSetName: "mongoDbRepSet"
setParameter:
enableLocalhostAuthBypass: false
processManagement:
windowsService:
serviceName: "MongoDB"
displayName: "MongoDB 3.2 Standard"
description: "This is the service for MongoDB 3.2 Standard version"
I am using below command
mongod --config "C:\Program Files\MongoDB\Server\3.2\mongod.cfg" --install
I am restarting the mongo service after installing it with the configuraiton.
Strange thing is, when I open in RoboMongo and try to connect using 127.0.0.0 and 10.64.87.231 it is not working.
Also noticed that, it is connecting with ip addresses 127.0.0.1 to 127.0.0.255 (so many loopback ips?)
I also checked by assigning enableLocalhostAuthBypass: true but still not working.
What is wrong happening no idea. Please help me to restrict mongo service to give ip address.