Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create MongoDB database and set its path to a specific folder

Tags:

mongodb

I'm using ubuntu 16.04! Is it possible to change the data directory for a specific database in mongo? I'm trying to setup this recommendation engine and I was asked to create a new MongoDB database and set its path to folder.

like image 628
geek-tech Avatar asked Jan 03 '17 10:01

geek-tech


3 Answers

Pre-version 3.0.0, all the databases that one mongod hosts have to be in the same dbpath folder which can be set via command arguments using the --dbpath flag or the config file.

You could however run multiple mongods and host them individually? either on different ip/ports.

Version 3.0.0 you can use the --directoryperdb flag within the command arguments or config to set multiple directories per database (See https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption--directoryperdb)

Uses a separate directory to store data for each database. The directories are under the --dbpath directory, and each subdirectory name corresponds to the database name.

like image 140
Kevin Smith Avatar answered Oct 20 '22 17:10

Kevin Smith


When you start mongod.exe you can set the database path with the

mongod.exe --dbpath "path to your folder"

setting.

like image 3
GarbageCollector Avatar answered Oct 20 '22 17:10

GarbageCollector


yes it's possible, run mongod process with --dbpath option

like image 1
Rahul Kumar Avatar answered Oct 20 '22 16:10

Rahul Kumar