Setting path for replica set different from root in windows doesnt work - mongodb

As I created replicaSet outside of /data/db folder by mistake, so I would like to set path to folder which is not root where I created replica set, instead of starting again.
I tried this(inside mongodb-instance folder is 3 replica folders):
"D:\MongoDB\Server\3.4\bin\mongod.exe" --dbpath D:\mongodb-instance
then I try to run It:
mongod --replSet "rs0"
but still got the same problem:
Data directory C:\data\db\ not found.

For replication, you need to setup multiple servers. Then each of them will have their own data folders.
Then start the servers using command
mongod --host <hostname> --port <portNum> --replSet "nameOfReplicaSet"
Once all the servers are running you'll have to initiate the replication by connecting to any one of them and execute the rs.initiate(replConfig) command with whatever configuration you need.
You can refer to the docs here.

Related

MongoDB replication as a service on windows

I am trying to configure a replica set on windows as a service, means that even the PC will restart the mongod will run again automatically.
problem is that I run the mongod like this:
mongod --dbpath "C:\Program Files\MongoDB\Server\4.2\data" --logpath "C:\Program Files\MongoDB\Server\4.2\log\mongod.log" --port 27017 --storageEngine=wiredTiger --journal --replSet test_replica
And once I close the CMD running this command the service is killed. How do I run it correctly then?
Also, currenctly the service is navigating to the default cfg file but I see the replication there is marked with # (so the service is running as standalone). and when I try to add to replication the replSet: test_replica it won't start anymore.
You should put all your parameters into a configuration file. Then you can create the service like this:
mongod.exe --config c:\MongoDB\config\mongod.cfg --install
For a replica set you typically create several services, not just one. It is possible to run a replica set with just one member, however this is quite useless. Of course, when you create several services then each one needs his own config file (and also his own dbPath, port, etc.)
The next time your PC will boot, the mongo service should also start. Or start it manually with command net start <mongo service name>
You should install mongodb as windows service. Read the guide from the official documentation
Setting --replSet from command line or replication:replSetName in configuration file is not enough. Read this guide, in short: after mongodb process is started in replica set mode, you should run rs.initiate() in mongo shell.

How to set mongo db path permanently

Is there a way to over-rite the mongodb default db path. Even after editing the storage path in mongod.conf to the custom directory path. Still it looks for /data/db, and not the custom path.
Since every time mongod path needs to be specified for the custom path.
mongod --dbpath /Users/customData
Is there a permanent way to deal this.
You can try to run it as a service, so that you don't need to run this command everytime you want to use it, and it runs it in the path you set it to
Here's how:
the link
from official mongodb website: the link
According to documentation of MongoDB
To run a mongod process as a daemon (i.e. fork), and write its output
to a log file, use the --fork and --logpath options. You must create
the log directory; however, mongod will create the log file if it does
not exist.
The following command starts mongod as a daemon and records log output
to /var/log/mongodb.log.
mongod --fork --logpath /var/log/mongodb.log

Unable to change dbpath in MongoDB using command line

I started learning mongoDB a couple of days ago. Post installation, I am trying to change the dbpath as follows:
mongod --dbpath C:\myfolder\myproj\data\db
running the above command, I got the below statements in the command line:
Now i typed the below command to check if the dbpath has changed
mongod dbpath
this line still returns:
C:\data\db
I also tried running the below command to change the dbpath (as mentioned in a youtube video https://www.youtube.com/watch?v=pWbMrx5rVBE, but still the dbpath didn't change
mongod --directoryperdb --dbpath c:\myfolder\myproj\data\db
Can someone tell me how can I change my dbpath?
I looked at the stackoverflow question MongoDB not using /etc/mongodb.conf after I changed dbpath and also Unable to change the dbpath in mongodb through mongodb.conf but none of them helped
When you run
mongod --dbpath C:\myfolder\myproj\data\db
You are starting an instance of mongod with it's data directory as C:\myfolder\myproj\data\db
Running a second
mongod dbpath
is effectively starting a new instance of mongod - which, by default, has its dbpath as \data\db
Just run mongod --dbpath C:\myfolder\myproj\data\db as you are, then use mongo to connect to it (or whatever client you're using)
When connecting to that instance, you'll be using the instance that is storing it's data in C:\myfolder\myproj\data\db

How can I access copied mongodb folder

I just got copied database folder(literally copy and paste) of mongodb.
Actually, I'm beginner of mongodb and have a lot of problem to access copied database.
Could you give me any advice?
To start the database with the new directory - you can do the following:
Change dbpath in config: link, then restart mongod service
Run single mongod instance like "mongod --dbpath /data/db".
If you use WireTiger engine - "mongod --dbpath /data/db --storageEngine wiredTiger"

How to deploy three config server instances for sharding in mongodb?

I am a newbie in MongoDB. Also I have not much knowledge in networking and servers. I am trying to deploy sharded cluster in mongodb using this article.
It says I need to deploy three configuration server instances and create data directories for each.
I can create a data directory using this command
mkdir /data/configdb
But how do I do this for all three of them?
Also I want to do this in only one machine.
As dev mentioned, for testing purposes a single config server is pretty much enough, and three config servers should be considered for production deployment.
But anyway, there is no problem creating separate directories for each config server on one machine. As you have mentioned, yes you can create directories, but data directory for any mongo instance (mongod, configsvr, etc.) is not limited to any path. So that means you can create separate directories and launch mongod config servers by specifying path for each:
$ mkdir /data/configdb1
$ mkdir /data/configdb2
$ mkdir /data/configdb3
$ mongod --configsvr --dbpath /data/configdb1 ...
$ mongod --configsvr --dbpath /data/configdb2 ...
$ mongod --configsvr --dbpath /data/configdb3 ...