Where are mongo replication settings stored? - mongodb

After a complete reinstall of mongo, it has still remembered the replica set configuration from before; where has it stored this?
I installed mongo on a linux server, using our project's user account, into a directory owned by that user. I set up replication and had it working fine. Then, to test out some finer install points, I removed the whole mongo directory and did a reinstall. Entering into mongo, I found that the replication was already set up as before; so it would appear that mongo is storing the information somewhere.
I have checked several areas which might have been holding the replica set config:
First, in the mongo directory, but that was deleted.
In some traditional linux structure probably owned by root, but the project user does not have root access and mongo, run by the same, should not either.
The project user's home directory. Now this does have a .dbshell file containing the command line history, but only that. I did not see any other files there that related.
Some location specified in the mongo configuration. But I only have two paths mentioned in there, one for the system log (systemLog.path) and the other for storage (storage.dbPath), and the both point to the mongo directory, which was deleted.
Does anyone know where mongo is storing this configuration information?

The replication data is stored in the local database in each node (as of MongoDB 3.2.9). This database contains information about the replica set, and also contains the oplog (the oplog.rs collection). The replica set information is stored in the system.replset collection in this local database.
The physical files for this database (and also for other databases) are stored in the dbPath directory, which can be configured using:
The --dbpath parameter when starting mongod
The storage.dbPath setting in the configuration file
The default dbpath value is /data/db
Your replica set setting will not be retained if you emptied the dbpath directory. If you find that the replication settings are being retained, it is possible that the dbpath setting is incorrect.

Related

How to specificy path of new collection in Mongo DB?

I am running Mongo on Windows 10. Data access is made trugh Pymongo (Python). All my data is stored in an old large HDD, but I would like to have some smaller collection stored on a much faster SSD? When I create a new collection either trough Compass or Pymongo there is no option to specify the path on disk.
Is it possible to learn such power?
If you want to have databases in different disks under the same dbPath , this is the option:
Add the option --directoryperdb in the mongod config file or at startup.
db.createDatabase("newDatabase")
You will see inside the dbPath folder for the new database like:
\dbPath\newDatabase
Stop the mongodb process.
Copy the content from \dbPath\neWDatabase to your SSD let say:
ssd:\newData
make link to the folder with:
mklink /d \newData \dbPath\newDatabase
or follow this tutotial
Start the mongodb process again.
Note:
As suggested by #Wermfried in the comment it is safe to have the option --directoryperdb set initially in the member before to get populated ...

MongoDB restore from file backup

I have a backup of /data/db that contains all .wt files along with journal directory etc. I have stopped the db, replaced the current db directory with the one backed up and started the db. This works, Mongo starts up but when I "show databases" there are no results. The local machine (that was backed up) did not have authentication enabled. The machine I am using to attempt the restore does have it enabled, I am able to start the mongo client without any authentication.
Is there another step to this process?
Is the authentication difference an issue?

MongoDB: Stop from storing replica set settings

I have a local mongo database that's being populated by a script which will run for the next few days.
When it'll be done, I'm expecting its size to be quite substantial, so I want mongo to stop storing replica sets (or whatever is it doing in that database called "local"), because this is just a pet project, the database is local. I won't have any clients so I don't need replication and the database will only be used for reads after the initial data is inserted. It has the same size as my database so it's a waste of space.
I found this other thread where they just basically say to drop the local database and I did that but, every time I'm starting mongod, it's there again (and I'm not starting mongod with --replSet. Mongod doesn't even recognize that flag, btw). Could you please tell me how do I stop mongod from generating it?
Running mongod as a standalone (no --replSet option) means you won't store oplog entries or replica set related information.
The local database will be created. The size of the local database should remain static in this case. The contents should be 2 collections:
startup_log which holds static information about your mongod instance, including version, start time and startup options.
system.indexes which contains index definitions for the collections in this database. In this case it would have a single entry defining the _id index for startup_log.
To confirm yourself that these are the only 2 collections run the following from the mongo shell:
use local;
show collections;

Data storage in mongodb

first of all please forgive me for asking a silly question but I am new to mongodb and just installed it on my windows platform by following this installation guide :http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/
It says "MongoDB requires a data folder to store its files. The default location for the MongoDB data directory is C:\data\db.You can specify an alternate path for data files using the --dbpath option to mongod.exe."
So I created a folder d://data/db in my computer and issued a command
C:\mongodb\bin\mongod.exe --dbpath d:\mongodb\data
Then it says
"At the mongo.exe prompt, issue the following two commands to insert a record in the test collection of the default test database and then retrieve that record:
db.test.save( { a: 1 } )
db.test.find()"
I issued this to commands to save and retrieve the objects and its working fine but what is this default test database? where is it? Moreover where this object is stored? Where I can find this file?
what is this default test database?
When you connect to a mongod server without specifying a database, a default database "test" is selected. Since databases are created lazily, it may not even exist until you write to it.
db.test.save( { a: 1 } )
After this line is executed, database with current name ("test" by default) is created (if didn't exist already) and in it, collection "test" is created (if didn't exist already).
where is it? Moreover where this object is stored? Where I can find this file?
All databases are ultimately stored as files in your data dir. Look for "test.*" files there.
mongod.lock, is the file which provides the PID of your running mongod instance. When you start a mongod instance, MongoDB check if the lock is empty to start cleanly mongod. Then MongoDB registered the PID number of the running mongod instance in this lock file.
MongoDB delete the contains of this lock file when you shutdown cleanly your server,
mongod --shutdown -- dbpath <path name> --port <port number>

Restoring from a single instance mongodb to an empty replica set

I have a mongodb installed on windows server. I take regular backups of the data/db folder using Rackspace backup.
I created a deployment of a mongodb replica set with 3 ubuntu servers using Rackspace deployments. Now I want to move the data on windows to the empty replica set. How can I do it?
I tried copying the contents of data/db on windows to var/lib/mongodb on the primary replica set. It didn't work.
For some reason the var/lib/mongodb on the ubuntu machines does not contain data/db directory. When I create a new db the db files are created on var/lib/mongodb directory.
The difference in data directories is fine .. on Windows the default dbpath will be c:\data\db; the Ubuntu package sets the dbpath to /var/lib/mongodb instead.
Since you are starting with an empty replica set (and using a backup from a standalone server), the most straightforward approach would be to:
Stop all the mongod servers for the replica set (you definitely don't want to copy data files directly into a running instance!).
Remove any files that are already in the /var/lib/mongodb data directory.
Copy the data files from your standalone MongoDB backup into /var/lib/mongodb on one of your replica set servers. This server will become your primary to set up the rest of the replica set.
Start up this primary making sure to include a replSet name in your configuration file. You may already have this set from your "empty" replica set that you already created.
Run rs.initiate() in the mongo shell to create the initial configuration on the primary.
Start up your additional servers as members of this replica set: they need the same replSet name configured.
Use rs.add(..) to add your additional servers from the mongo shell on your primary. Assuming the add is successful (i.e. the mongods can connect to each other), this will begin the process of initial sync (copying data from the primary) and the new hosts will become secondaries after they have finishing initial sync.
This is essentially the same steps as the deploy a replica set tutorial, except you are copying over your data first.
The problem could be related to the configuration file of mongodb
locate the file mongodb.conf and edit the dbpath parameter, check if the path really exist, and if it doesn't create the missing directories. Also check permissions in that path
anyway i don't know if its the right way to just copy the datafiles in a new location, i guess you should use mongo import/export