how to set mongod --dbpath










16














very new to mongodb and databases in general. whenever i run mongo i receive this error message: ​​​



MongoDB shell version: 2.4.9
connecting to: test
Thu Jan 30 13:03:33.170 Error: couldn't connect to server 127.0.0.1:27017
at src/mongo/shell/mongo.js:145
exception: connect failed


running mongod i see this:



Thu Jan 30 13:13:36.588 [initandlisten] MongoDB starting : pid=29408 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=Kimis-MacBook-Air-2.local
Thu Jan 30 13:13:36.588 [initandlisten]
Thu Jan 30 13:13:36.588 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Thu Jan 30 13:13:36.588 [initandlisten] db version v2.4.9
Thu Jan 30 13:13:36.588 [initandlisten] git version: nogitversion
Thu Jan 30 13:13:36.588 [initandlisten] build info: Darwin minilionvm.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Thu Jan 30 13:13:36.588 [initandlisten] allocator: tcmalloc
Thu Jan 30 13:13:36.588 [initandlisten] options: bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb"
Thu Jan 30 13:13:36.591 [initandlisten] journal dir=/usr/local/var/mongodb/journal
Thu Jan 30 13:13:36.591 [initandlisten] recover begin
Thu Jan 30 13:13:36.591 [initandlisten] recover lsn: 108155770
Thu Jan 30 13:13:36.591 [initandlisten] recover /usr/local/var/mongodb/journal/j._0
Thu Jan 30 13:13:36.591 [initandlisten] journal file version number mismatch got:4147 expected:4149. if you have just upgraded, recover with old version of mongod, terminate cleanly, then upgrade.
Thu Jan 30 13:13:36.592 [initandlisten] dbexception during recovery: 13536 journal version number mismatch 16711
Thu Jan 30 13:13:36.592 [initandlisten] exception in initAndListen: 13536 journal version number mismatch 16711, terminating
Thu Jan 30 13:13:36.592 dbexit:
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to close listening sockets...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to flush diaglog...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to close sockets...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: lock for final commit...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: final commit...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: closing all files...
Thu Jan 30 13:13:36.592 [initandlisten] closeAllFiles() finished
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: removing fs lock...
Thu Jan 30 13:13:36.592 dbexit: really exiting now


when i manually set my mongo dpath to mongod --dbpath /data/db (as should be the default on installation) and keep it running in terminal everything runs fine. but once i close it, everything breaks again. my question is:



  1. why is my dbpath set to /usr/local/var/mongodb?

  2. how do i fix this error so mongo works on my machine?

i'm assuming i either need to permanently set the dbpath to /data/db or reconfigure something so it works with the dbpath as /usr/local/var/mongodb



i fairly new to unix commands as well so not entirely sure how to fix this error.



thank you for any suggestions!



so, digging through the mongodb documentation i read this:



"Unless specified, mongod will look for data files in the default /data/db directory. (Windows systems use the datadb directory.) If you installed using a package management system. Check the /etc/mongodb.conf file provided by your packages to see the configuration of the dbpath."



when i took a look at the files within /etc/ there is no mongodb.conf file... however, i do see /usr/local/etc/mongod.conf... so if i understand this correctly, i should create a file called /etc/mongodb.conf and set the dbpath to /data/db.



do i need to delete the stuff within /usr/local/ as well?



i think this has something to do with how my PATH are setup... could someone explain to me how to fix this in unix so i won't have this problem?



thanks again!










share|improve this question























  • Could you post the full error log?
    – 4J41
    Jan 30 '14 at 5:11










  • i've just appended my question with the full error log. please let me know if any other info will help. thanks!
    – vesperae
    Jan 30 '14 at 5:15










  • There is no baked-in config path for MongoDB, so if your service definition uses /usr/local/etc/mongod.conf that will be the correct file to edit (creating a new file in etc won't be helpful). You can check what options the MongoDB server was started with in the mongo shell using: db.adminCommand('getCmdLineOpts').
    – Stennie
    Feb 1 '14 at 6:53






  • 1




    you can start the daemon by specifying its direcotry with mongod --dpath /whatever/data/path
    – bachr
    Sep 5 '14 at 18:17















16














very new to mongodb and databases in general. whenever i run mongo i receive this error message: ​​​



MongoDB shell version: 2.4.9
connecting to: test
Thu Jan 30 13:03:33.170 Error: couldn't connect to server 127.0.0.1:27017
at src/mongo/shell/mongo.js:145
exception: connect failed


running mongod i see this:



Thu Jan 30 13:13:36.588 [initandlisten] MongoDB starting : pid=29408 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=Kimis-MacBook-Air-2.local
Thu Jan 30 13:13:36.588 [initandlisten]
Thu Jan 30 13:13:36.588 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Thu Jan 30 13:13:36.588 [initandlisten] db version v2.4.9
Thu Jan 30 13:13:36.588 [initandlisten] git version: nogitversion
Thu Jan 30 13:13:36.588 [initandlisten] build info: Darwin minilionvm.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Thu Jan 30 13:13:36.588 [initandlisten] allocator: tcmalloc
Thu Jan 30 13:13:36.588 [initandlisten] options: bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb"
Thu Jan 30 13:13:36.591 [initandlisten] journal dir=/usr/local/var/mongodb/journal
Thu Jan 30 13:13:36.591 [initandlisten] recover begin
Thu Jan 30 13:13:36.591 [initandlisten] recover lsn: 108155770
Thu Jan 30 13:13:36.591 [initandlisten] recover /usr/local/var/mongodb/journal/j._0
Thu Jan 30 13:13:36.591 [initandlisten] journal file version number mismatch got:4147 expected:4149. if you have just upgraded, recover with old version of mongod, terminate cleanly, then upgrade.
Thu Jan 30 13:13:36.592 [initandlisten] dbexception during recovery: 13536 journal version number mismatch 16711
Thu Jan 30 13:13:36.592 [initandlisten] exception in initAndListen: 13536 journal version number mismatch 16711, terminating
Thu Jan 30 13:13:36.592 dbexit:
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to close listening sockets...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to flush diaglog...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to close sockets...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: lock for final commit...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: final commit...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: closing all files...
Thu Jan 30 13:13:36.592 [initandlisten] closeAllFiles() finished
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: removing fs lock...
Thu Jan 30 13:13:36.592 dbexit: really exiting now


when i manually set my mongo dpath to mongod --dbpath /data/db (as should be the default on installation) and keep it running in terminal everything runs fine. but once i close it, everything breaks again. my question is:



  1. why is my dbpath set to /usr/local/var/mongodb?

  2. how do i fix this error so mongo works on my machine?

i'm assuming i either need to permanently set the dbpath to /data/db or reconfigure something so it works with the dbpath as /usr/local/var/mongodb



i fairly new to unix commands as well so not entirely sure how to fix this error.



thank you for any suggestions!



so, digging through the mongodb documentation i read this:



"Unless specified, mongod will look for data files in the default /data/db directory. (Windows systems use the datadb directory.) If you installed using a package management system. Check the /etc/mongodb.conf file provided by your packages to see the configuration of the dbpath."



when i took a look at the files within /etc/ there is no mongodb.conf file... however, i do see /usr/local/etc/mongod.conf... so if i understand this correctly, i should create a file called /etc/mongodb.conf and set the dbpath to /data/db.



do i need to delete the stuff within /usr/local/ as well?



i think this has something to do with how my PATH are setup... could someone explain to me how to fix this in unix so i won't have this problem?



thanks again!










share|improve this question























  • Could you post the full error log?
    – 4J41
    Jan 30 '14 at 5:11










  • i've just appended my question with the full error log. please let me know if any other info will help. thanks!
    – vesperae
    Jan 30 '14 at 5:15










  • There is no baked-in config path for MongoDB, so if your service definition uses /usr/local/etc/mongod.conf that will be the correct file to edit (creating a new file in etc won't be helpful). You can check what options the MongoDB server was started with in the mongo shell using: db.adminCommand('getCmdLineOpts').
    – Stennie
    Feb 1 '14 at 6:53






  • 1




    you can start the daemon by specifying its direcotry with mongod --dpath /whatever/data/path
    – bachr
    Sep 5 '14 at 18:17













16












16








16


4





very new to mongodb and databases in general. whenever i run mongo i receive this error message: ​​​



MongoDB shell version: 2.4.9
connecting to: test
Thu Jan 30 13:03:33.170 Error: couldn't connect to server 127.0.0.1:27017
at src/mongo/shell/mongo.js:145
exception: connect failed


running mongod i see this:



Thu Jan 30 13:13:36.588 [initandlisten] MongoDB starting : pid=29408 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=Kimis-MacBook-Air-2.local
Thu Jan 30 13:13:36.588 [initandlisten]
Thu Jan 30 13:13:36.588 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Thu Jan 30 13:13:36.588 [initandlisten] db version v2.4.9
Thu Jan 30 13:13:36.588 [initandlisten] git version: nogitversion
Thu Jan 30 13:13:36.588 [initandlisten] build info: Darwin minilionvm.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Thu Jan 30 13:13:36.588 [initandlisten] allocator: tcmalloc
Thu Jan 30 13:13:36.588 [initandlisten] options: bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb"
Thu Jan 30 13:13:36.591 [initandlisten] journal dir=/usr/local/var/mongodb/journal
Thu Jan 30 13:13:36.591 [initandlisten] recover begin
Thu Jan 30 13:13:36.591 [initandlisten] recover lsn: 108155770
Thu Jan 30 13:13:36.591 [initandlisten] recover /usr/local/var/mongodb/journal/j._0
Thu Jan 30 13:13:36.591 [initandlisten] journal file version number mismatch got:4147 expected:4149. if you have just upgraded, recover with old version of mongod, terminate cleanly, then upgrade.
Thu Jan 30 13:13:36.592 [initandlisten] dbexception during recovery: 13536 journal version number mismatch 16711
Thu Jan 30 13:13:36.592 [initandlisten] exception in initAndListen: 13536 journal version number mismatch 16711, terminating
Thu Jan 30 13:13:36.592 dbexit:
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to close listening sockets...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to flush diaglog...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to close sockets...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: lock for final commit...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: final commit...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: closing all files...
Thu Jan 30 13:13:36.592 [initandlisten] closeAllFiles() finished
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: removing fs lock...
Thu Jan 30 13:13:36.592 dbexit: really exiting now


when i manually set my mongo dpath to mongod --dbpath /data/db (as should be the default on installation) and keep it running in terminal everything runs fine. but once i close it, everything breaks again. my question is:



  1. why is my dbpath set to /usr/local/var/mongodb?

  2. how do i fix this error so mongo works on my machine?

i'm assuming i either need to permanently set the dbpath to /data/db or reconfigure something so it works with the dbpath as /usr/local/var/mongodb



i fairly new to unix commands as well so not entirely sure how to fix this error.



thank you for any suggestions!



so, digging through the mongodb documentation i read this:



"Unless specified, mongod will look for data files in the default /data/db directory. (Windows systems use the datadb directory.) If you installed using a package management system. Check the /etc/mongodb.conf file provided by your packages to see the configuration of the dbpath."



when i took a look at the files within /etc/ there is no mongodb.conf file... however, i do see /usr/local/etc/mongod.conf... so if i understand this correctly, i should create a file called /etc/mongodb.conf and set the dbpath to /data/db.



do i need to delete the stuff within /usr/local/ as well?



i think this has something to do with how my PATH are setup... could someone explain to me how to fix this in unix so i won't have this problem?



thanks again!










share|improve this question















very new to mongodb and databases in general. whenever i run mongo i receive this error message: ​​​



MongoDB shell version: 2.4.9
connecting to: test
Thu Jan 30 13:03:33.170 Error: couldn't connect to server 127.0.0.1:27017
at src/mongo/shell/mongo.js:145
exception: connect failed


running mongod i see this:



Thu Jan 30 13:13:36.588 [initandlisten] MongoDB starting : pid=29408 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=Kimis-MacBook-Air-2.local
Thu Jan 30 13:13:36.588 [initandlisten]
Thu Jan 30 13:13:36.588 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Thu Jan 30 13:13:36.588 [initandlisten] db version v2.4.9
Thu Jan 30 13:13:36.588 [initandlisten] git version: nogitversion
Thu Jan 30 13:13:36.588 [initandlisten] build info: Darwin minilionvm.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Thu Jan 30 13:13:36.588 [initandlisten] allocator: tcmalloc
Thu Jan 30 13:13:36.588 [initandlisten] options: bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb"
Thu Jan 30 13:13:36.591 [initandlisten] journal dir=/usr/local/var/mongodb/journal
Thu Jan 30 13:13:36.591 [initandlisten] recover begin
Thu Jan 30 13:13:36.591 [initandlisten] recover lsn: 108155770
Thu Jan 30 13:13:36.591 [initandlisten] recover /usr/local/var/mongodb/journal/j._0
Thu Jan 30 13:13:36.591 [initandlisten] journal file version number mismatch got:4147 expected:4149. if you have just upgraded, recover with old version of mongod, terminate cleanly, then upgrade.
Thu Jan 30 13:13:36.592 [initandlisten] dbexception during recovery: 13536 journal version number mismatch 16711
Thu Jan 30 13:13:36.592 [initandlisten] exception in initAndListen: 13536 journal version number mismatch 16711, terminating
Thu Jan 30 13:13:36.592 dbexit:
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to close listening sockets...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to flush diaglog...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to close sockets...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: lock for final commit...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: final commit...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: closing all files...
Thu Jan 30 13:13:36.592 [initandlisten] closeAllFiles() finished
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: removing fs lock...
Thu Jan 30 13:13:36.592 dbexit: really exiting now


when i manually set my mongo dpath to mongod --dbpath /data/db (as should be the default on installation) and keep it running in terminal everything runs fine. but once i close it, everything breaks again. my question is:



  1. why is my dbpath set to /usr/local/var/mongodb?

  2. how do i fix this error so mongo works on my machine?

i'm assuming i either need to permanently set the dbpath to /data/db or reconfigure something so it works with the dbpath as /usr/local/var/mongodb



i fairly new to unix commands as well so not entirely sure how to fix this error.



thank you for any suggestions!



so, digging through the mongodb documentation i read this:



"Unless specified, mongod will look for data files in the default /data/db directory. (Windows systems use the datadb directory.) If you installed using a package management system. Check the /etc/mongodb.conf file provided by your packages to see the configuration of the dbpath."



when i took a look at the files within /etc/ there is no mongodb.conf file... however, i do see /usr/local/etc/mongod.conf... so if i understand this correctly, i should create a file called /etc/mongodb.conf and set the dbpath to /data/db.



do i need to delete the stuff within /usr/local/ as well?



i think this has something to do with how my PATH are setup... could someone explain to me how to fix this in unix so i won't have this problem?



thanks again!







mongodb unix






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 26 '16 at 10:21









Fabian N.

2,40611432




2,40611432










asked Jan 30 '14 at 5:09









vesperae

4451823




4451823











  • Could you post the full error log?
    – 4J41
    Jan 30 '14 at 5:11










  • i've just appended my question with the full error log. please let me know if any other info will help. thanks!
    – vesperae
    Jan 30 '14 at 5:15










  • There is no baked-in config path for MongoDB, so if your service definition uses /usr/local/etc/mongod.conf that will be the correct file to edit (creating a new file in etc won't be helpful). You can check what options the MongoDB server was started with in the mongo shell using: db.adminCommand('getCmdLineOpts').
    – Stennie
    Feb 1 '14 at 6:53






  • 1




    you can start the daemon by specifying its direcotry with mongod --dpath /whatever/data/path
    – bachr
    Sep 5 '14 at 18:17
















  • Could you post the full error log?
    – 4J41
    Jan 30 '14 at 5:11










  • i've just appended my question with the full error log. please let me know if any other info will help. thanks!
    – vesperae
    Jan 30 '14 at 5:15










  • There is no baked-in config path for MongoDB, so if your service definition uses /usr/local/etc/mongod.conf that will be the correct file to edit (creating a new file in etc won't be helpful). You can check what options the MongoDB server was started with in the mongo shell using: db.adminCommand('getCmdLineOpts').
    – Stennie
    Feb 1 '14 at 6:53






  • 1




    you can start the daemon by specifying its direcotry with mongod --dpath /whatever/data/path
    – bachr
    Sep 5 '14 at 18:17















Could you post the full error log?
– 4J41
Jan 30 '14 at 5:11




Could you post the full error log?
– 4J41
Jan 30 '14 at 5:11












i've just appended my question with the full error log. please let me know if any other info will help. thanks!
– vesperae
Jan 30 '14 at 5:15




i've just appended my question with the full error log. please let me know if any other info will help. thanks!
– vesperae
Jan 30 '14 at 5:15












There is no baked-in config path for MongoDB, so if your service definition uses /usr/local/etc/mongod.conf that will be the correct file to edit (creating a new file in etc won't be helpful). You can check what options the MongoDB server was started with in the mongo shell using: db.adminCommand('getCmdLineOpts').
– Stennie
Feb 1 '14 at 6:53




There is no baked-in config path for MongoDB, so if your service definition uses /usr/local/etc/mongod.conf that will be the correct file to edit (creating a new file in etc won't be helpful). You can check what options the MongoDB server was started with in the mongo shell using: db.adminCommand('getCmdLineOpts').
– Stennie
Feb 1 '14 at 6:53




1




1




you can start the daemon by specifying its direcotry with mongod --dpath /whatever/data/path
– bachr
Sep 5 '14 at 18:17




you can start the daemon by specifying its direcotry with mongod --dpath /whatever/data/path
– bachr
Sep 5 '14 at 18:17












7 Answers
7






active

oldest

votes


















7














First you will have a config file in /etc/mongodb.conf, therefore this sounds like a homebrew install which will use some more standardized paths. The whole /data/db/ thing is referenced in a lot of manual install documentation.



So basically from your log the server is not running, it's shutting down, so there is nothing for the shell to connect to. Seems like you have had some unclean shutdowns/restarts which has led to the inconsistency.



Clear the files in the journal /usr/local/var/mongodb/journal/ on your config.



Also:



sudo rm /var/lib/mongodb/mongod.lock


Just in case, even though that part looks clean. And then restart.






share|improve this answer






















  • you rock! thanks so much.
    – vesperae
    Jan 30 '14 at 6:43


















12














Have only tried this on Mac:



  • Create a data directory in the root folder of your app

  • cd into your wherever you placed your mongo directory when you installed it


  • run this command:



    mongod --dbpath ~/path/to/your/app/data



You should be good to go!






share|improve this answer
















  • 2




    If you are coding with version control (Github/Bitbucket), you should not set this path in your repo.
    – Jed Lynch
    Dec 22 '16 at 3:59










  • Thanks Sacha. This worked for me. Sean
    – Sean
    Apr 6 '17 at 10:30


















8














You can set dbPath in the mongodb.conf file:



storage:
dbPath: "/path/to/your/database/data/db"


It's a YAML-based configuration file format (since Mongodb 2.6 version), so pay attention no tabs only spaces, and space after ": "



usually this file located in the *nix systems here: /etc/mongodb.conf



So then just run



$ mongod -f /etc/mongodb.conf


And mongod process will start...



(on the Windows something like)



> C:MongoDBbinmongod.exe -f C:MongoDBmongod.conf





share|improve this answer






















  • I have a doubt on mongo command, suppose I have created two db paths with mongod --dbpath abc and mongod --dbpath xyz, when I checked the /usr/local/etc/mongod.conf file it still shows storage: dbPath: /usr/local/var/mongodb how I can tell mongo command to load db from abc or xyz directory? should I change mongod.conf file manually?
    – Johnykutty
    Jul 4 '17 at 13:55



















6














For me it must have:



mongod --dbpath=/whatever/data/path





share|improve this answer






















  • --dbpath not --dpath ?
    – Alexander Mills
    Jul 26 '17 at 23:54










  • Yes, should be dbpath. Using the = sign worked for me on MacOS with Brew.
    – Adam Erickson
    May 9 at 23:19






  • 1




    mongod --dbpath=/whatever/data/path
    – Mithun Khatri
    Jun 2 at 12:56


















1














You could also configure mongod to run on start up so that it is automatically running on start up and the dbpath is set upon configuration. To do this try:




mongod --smallfiles --config /etc/mongod.conf




The --smallfiles tag is there in case you get an error with size. It is, of course, optional. Doing this should solve your problem while also automating your mongodb setup.






share|improve this answer




























    1














    mongod --port portnumber --dbpath /path_to_your_folder


    By default portnumber is 27017 and path is /var/lib/mongodb



    You can set your own port number and path where you want to keep all your database.






    share|improve this answer






















    • does it needs to set dbpath every time you run the mongod or just once at the beginning and after that you run just mongod without specifying dbpath ?
      – ler
      Dec 15 '17 at 16:27


















    0














    very simple:



    sudo chown mongodb:mongodb /var/lib/mongodb/mongod.lock 





    share|improve this answer


















    • 2




      Perhaps it would be of benefit if you give a bit of an explanation as this has been flagged as low qualify.
      – Gerhard Barnard
      Nov 12 at 11:03










    • at the first when the problem is occurring I deleted mongod. lock sudo rm /var/lib/mongodb/mongod.lock after that I launched it with sudo mongod --dbpath=/var/lib/mongodb but I am obliged to run it every time but I observed that mongod. lock was re-created and the owner is root and not mongodb
      – Mezlini
      Nov 13 at 16:50










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21448268%2fhow-to-set-mongod-dbpath%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    7 Answers
    7






    active

    oldest

    votes








    7 Answers
    7






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    7














    First you will have a config file in /etc/mongodb.conf, therefore this sounds like a homebrew install which will use some more standardized paths. The whole /data/db/ thing is referenced in a lot of manual install documentation.



    So basically from your log the server is not running, it's shutting down, so there is nothing for the shell to connect to. Seems like you have had some unclean shutdowns/restarts which has led to the inconsistency.



    Clear the files in the journal /usr/local/var/mongodb/journal/ on your config.



    Also:



    sudo rm /var/lib/mongodb/mongod.lock


    Just in case, even though that part looks clean. And then restart.






    share|improve this answer






















    • you rock! thanks so much.
      – vesperae
      Jan 30 '14 at 6:43















    7














    First you will have a config file in /etc/mongodb.conf, therefore this sounds like a homebrew install which will use some more standardized paths. The whole /data/db/ thing is referenced in a lot of manual install documentation.



    So basically from your log the server is not running, it's shutting down, so there is nothing for the shell to connect to. Seems like you have had some unclean shutdowns/restarts which has led to the inconsistency.



    Clear the files in the journal /usr/local/var/mongodb/journal/ on your config.



    Also:



    sudo rm /var/lib/mongodb/mongod.lock


    Just in case, even though that part looks clean. And then restart.






    share|improve this answer






















    • you rock! thanks so much.
      – vesperae
      Jan 30 '14 at 6:43













    7












    7








    7






    First you will have a config file in /etc/mongodb.conf, therefore this sounds like a homebrew install which will use some more standardized paths. The whole /data/db/ thing is referenced in a lot of manual install documentation.



    So basically from your log the server is not running, it's shutting down, so there is nothing for the shell to connect to. Seems like you have had some unclean shutdowns/restarts which has led to the inconsistency.



    Clear the files in the journal /usr/local/var/mongodb/journal/ on your config.



    Also:



    sudo rm /var/lib/mongodb/mongod.lock


    Just in case, even though that part looks clean. And then restart.






    share|improve this answer














    First you will have a config file in /etc/mongodb.conf, therefore this sounds like a homebrew install which will use some more standardized paths. The whole /data/db/ thing is referenced in a lot of manual install documentation.



    So basically from your log the server is not running, it's shutting down, so there is nothing for the shell to connect to. Seems like you have had some unclean shutdowns/restarts which has led to the inconsistency.



    Clear the files in the journal /usr/local/var/mongodb/journal/ on your config.



    Also:



    sudo rm /var/lib/mongodb/mongod.lock


    Just in case, even though that part looks clean. And then restart.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Apr 18 at 23:56









    Jaba

    6,821175292




    6,821175292










    answered Jan 30 '14 at 5:35









    Neil Lunn

    96.9k22170181




    96.9k22170181











    • you rock! thanks so much.
      – vesperae
      Jan 30 '14 at 6:43
















    • you rock! thanks so much.
      – vesperae
      Jan 30 '14 at 6:43















    you rock! thanks so much.
    – vesperae
    Jan 30 '14 at 6:43




    you rock! thanks so much.
    – vesperae
    Jan 30 '14 at 6:43













    12














    Have only tried this on Mac:



    • Create a data directory in the root folder of your app

    • cd into your wherever you placed your mongo directory when you installed it


    • run this command:



      mongod --dbpath ~/path/to/your/app/data



    You should be good to go!






    share|improve this answer
















    • 2




      If you are coding with version control (Github/Bitbucket), you should not set this path in your repo.
      – Jed Lynch
      Dec 22 '16 at 3:59










    • Thanks Sacha. This worked for me. Sean
      – Sean
      Apr 6 '17 at 10:30















    12














    Have only tried this on Mac:



    • Create a data directory in the root folder of your app

    • cd into your wherever you placed your mongo directory when you installed it


    • run this command:



      mongod --dbpath ~/path/to/your/app/data



    You should be good to go!






    share|improve this answer
















    • 2




      If you are coding with version control (Github/Bitbucket), you should not set this path in your repo.
      – Jed Lynch
      Dec 22 '16 at 3:59










    • Thanks Sacha. This worked for me. Sean
      – Sean
      Apr 6 '17 at 10:30













    12












    12








    12






    Have only tried this on Mac:



    • Create a data directory in the root folder of your app

    • cd into your wherever you placed your mongo directory when you installed it


    • run this command:



      mongod --dbpath ~/path/to/your/app/data



    You should be good to go!






    share|improve this answer












    Have only tried this on Mac:



    • Create a data directory in the root folder of your app

    • cd into your wherever you placed your mongo directory when you installed it


    • run this command:



      mongod --dbpath ~/path/to/your/app/data



    You should be good to go!







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Oct 2 '14 at 0:16









    Sacha Nacar

    1,9031314




    1,9031314







    • 2




      If you are coding with version control (Github/Bitbucket), you should not set this path in your repo.
      – Jed Lynch
      Dec 22 '16 at 3:59










    • Thanks Sacha. This worked for me. Sean
      – Sean
      Apr 6 '17 at 10:30












    • 2




      If you are coding with version control (Github/Bitbucket), you should not set this path in your repo.
      – Jed Lynch
      Dec 22 '16 at 3:59










    • Thanks Sacha. This worked for me. Sean
      – Sean
      Apr 6 '17 at 10:30







    2




    2




    If you are coding with version control (Github/Bitbucket), you should not set this path in your repo.
    – Jed Lynch
    Dec 22 '16 at 3:59




    If you are coding with version control (Github/Bitbucket), you should not set this path in your repo.
    – Jed Lynch
    Dec 22 '16 at 3:59












    Thanks Sacha. This worked for me. Sean
    – Sean
    Apr 6 '17 at 10:30




    Thanks Sacha. This worked for me. Sean
    – Sean
    Apr 6 '17 at 10:30











    8














    You can set dbPath in the mongodb.conf file:



    storage:
    dbPath: "/path/to/your/database/data/db"


    It's a YAML-based configuration file format (since Mongodb 2.6 version), so pay attention no tabs only spaces, and space after ": "



    usually this file located in the *nix systems here: /etc/mongodb.conf



    So then just run



    $ mongod -f /etc/mongodb.conf


    And mongod process will start...



    (on the Windows something like)



    > C:MongoDBbinmongod.exe -f C:MongoDBmongod.conf





    share|improve this answer






















    • I have a doubt on mongo command, suppose I have created two db paths with mongod --dbpath abc and mongod --dbpath xyz, when I checked the /usr/local/etc/mongod.conf file it still shows storage: dbPath: /usr/local/var/mongodb how I can tell mongo command to load db from abc or xyz directory? should I change mongod.conf file manually?
      – Johnykutty
      Jul 4 '17 at 13:55
















    8














    You can set dbPath in the mongodb.conf file:



    storage:
    dbPath: "/path/to/your/database/data/db"


    It's a YAML-based configuration file format (since Mongodb 2.6 version), so pay attention no tabs only spaces, and space after ": "



    usually this file located in the *nix systems here: /etc/mongodb.conf



    So then just run



    $ mongod -f /etc/mongodb.conf


    And mongod process will start...



    (on the Windows something like)



    > C:MongoDBbinmongod.exe -f C:MongoDBmongod.conf





    share|improve this answer






















    • I have a doubt on mongo command, suppose I have created two db paths with mongod --dbpath abc and mongod --dbpath xyz, when I checked the /usr/local/etc/mongod.conf file it still shows storage: dbPath: /usr/local/var/mongodb how I can tell mongo command to load db from abc or xyz directory? should I change mongod.conf file manually?
      – Johnykutty
      Jul 4 '17 at 13:55














    8












    8








    8






    You can set dbPath in the mongodb.conf file:



    storage:
    dbPath: "/path/to/your/database/data/db"


    It's a YAML-based configuration file format (since Mongodb 2.6 version), so pay attention no tabs only spaces, and space after ": "



    usually this file located in the *nix systems here: /etc/mongodb.conf



    So then just run



    $ mongod -f /etc/mongodb.conf


    And mongod process will start...



    (on the Windows something like)



    > C:MongoDBbinmongod.exe -f C:MongoDBmongod.conf





    share|improve this answer














    You can set dbPath in the mongodb.conf file:



    storage:
    dbPath: "/path/to/your/database/data/db"


    It's a YAML-based configuration file format (since Mongodb 2.6 version), so pay attention no tabs only spaces, and space after ": "



    usually this file located in the *nix systems here: /etc/mongodb.conf



    So then just run



    $ mongod -f /etc/mongodb.conf


    And mongod process will start...



    (on the Windows something like)



    > C:MongoDBbinmongod.exe -f C:MongoDBmongod.conf






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jun 14 '15 at 20:06

























    answered Dec 16 '14 at 20:51









    Andrey

    17.8k79077




    17.8k79077











    • I have a doubt on mongo command, suppose I have created two db paths with mongod --dbpath abc and mongod --dbpath xyz, when I checked the /usr/local/etc/mongod.conf file it still shows storage: dbPath: /usr/local/var/mongodb how I can tell mongo command to load db from abc or xyz directory? should I change mongod.conf file manually?
      – Johnykutty
      Jul 4 '17 at 13:55

















    • I have a doubt on mongo command, suppose I have created two db paths with mongod --dbpath abc and mongod --dbpath xyz, when I checked the /usr/local/etc/mongod.conf file it still shows storage: dbPath: /usr/local/var/mongodb how I can tell mongo command to load db from abc or xyz directory? should I change mongod.conf file manually?
      – Johnykutty
      Jul 4 '17 at 13:55
















    I have a doubt on mongo command, suppose I have created two db paths with mongod --dbpath abc and mongod --dbpath xyz, when I checked the /usr/local/etc/mongod.conf file it still shows storage: dbPath: /usr/local/var/mongodb how I can tell mongo command to load db from abc or xyz directory? should I change mongod.conf file manually?
    – Johnykutty
    Jul 4 '17 at 13:55





    I have a doubt on mongo command, suppose I have created two db paths with mongod --dbpath abc and mongod --dbpath xyz, when I checked the /usr/local/etc/mongod.conf file it still shows storage: dbPath: /usr/local/var/mongodb how I can tell mongo command to load db from abc or xyz directory? should I change mongod.conf file manually?
    – Johnykutty
    Jul 4 '17 at 13:55












    6














    For me it must have:



    mongod --dbpath=/whatever/data/path





    share|improve this answer






















    • --dbpath not --dpath ?
      – Alexander Mills
      Jul 26 '17 at 23:54










    • Yes, should be dbpath. Using the = sign worked for me on MacOS with Brew.
      – Adam Erickson
      May 9 at 23:19






    • 1




      mongod --dbpath=/whatever/data/path
      – Mithun Khatri
      Jun 2 at 12:56















    6














    For me it must have:



    mongod --dbpath=/whatever/data/path





    share|improve this answer






















    • --dbpath not --dpath ?
      – Alexander Mills
      Jul 26 '17 at 23:54










    • Yes, should be dbpath. Using the = sign worked for me on MacOS with Brew.
      – Adam Erickson
      May 9 at 23:19






    • 1




      mongod --dbpath=/whatever/data/path
      – Mithun Khatri
      Jun 2 at 12:56













    6












    6








    6






    For me it must have:



    mongod --dbpath=/whatever/data/path





    share|improve this answer














    For me it must have:



    mongod --dbpath=/whatever/data/path






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jun 29 at 18:42









    CrazyCrow

    2,70011833




    2,70011833










    answered Oct 25 '16 at 10:10









    Gareth Thomas

    30022




    30022











    • --dbpath not --dpath ?
      – Alexander Mills
      Jul 26 '17 at 23:54










    • Yes, should be dbpath. Using the = sign worked for me on MacOS with Brew.
      – Adam Erickson
      May 9 at 23:19






    • 1




      mongod --dbpath=/whatever/data/path
      – Mithun Khatri
      Jun 2 at 12:56
















    • --dbpath not --dpath ?
      – Alexander Mills
      Jul 26 '17 at 23:54










    • Yes, should be dbpath. Using the = sign worked for me on MacOS with Brew.
      – Adam Erickson
      May 9 at 23:19






    • 1




      mongod --dbpath=/whatever/data/path
      – Mithun Khatri
      Jun 2 at 12:56















    --dbpath not --dpath ?
    – Alexander Mills
    Jul 26 '17 at 23:54




    --dbpath not --dpath ?
    – Alexander Mills
    Jul 26 '17 at 23:54












    Yes, should be dbpath. Using the = sign worked for me on MacOS with Brew.
    – Adam Erickson
    May 9 at 23:19




    Yes, should be dbpath. Using the = sign worked for me on MacOS with Brew.
    – Adam Erickson
    May 9 at 23:19




    1




    1




    mongod --dbpath=/whatever/data/path
    – Mithun Khatri
    Jun 2 at 12:56




    mongod --dbpath=/whatever/data/path
    – Mithun Khatri
    Jun 2 at 12:56











    1














    You could also configure mongod to run on start up so that it is automatically running on start up and the dbpath is set upon configuration. To do this try:




    mongod --smallfiles --config /etc/mongod.conf




    The --smallfiles tag is there in case you get an error with size. It is, of course, optional. Doing this should solve your problem while also automating your mongodb setup.






    share|improve this answer

























      1














      You could also configure mongod to run on start up so that it is automatically running on start up and the dbpath is set upon configuration. To do this try:




      mongod --smallfiles --config /etc/mongod.conf




      The --smallfiles tag is there in case you get an error with size. It is, of course, optional. Doing this should solve your problem while also automating your mongodb setup.






      share|improve this answer























        1












        1








        1






        You could also configure mongod to run on start up so that it is automatically running on start up and the dbpath is set upon configuration. To do this try:




        mongod --smallfiles --config /etc/mongod.conf




        The --smallfiles tag is there in case you get an error with size. It is, of course, optional. Doing this should solve your problem while also automating your mongodb setup.






        share|improve this answer












        You could also configure mongod to run on start up so that it is automatically running on start up and the dbpath is set upon configuration. To do this try:




        mongod --smallfiles --config /etc/mongod.conf




        The --smallfiles tag is there in case you get an error with size. It is, of course, optional. Doing this should solve your problem while also automating your mongodb setup.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 16 '14 at 18:01









        ABarb

        1506




        1506





















            1














            mongod --port portnumber --dbpath /path_to_your_folder


            By default portnumber is 27017 and path is /var/lib/mongodb



            You can set your own port number and path where you want to keep all your database.






            share|improve this answer






















            • does it needs to set dbpath every time you run the mongod or just once at the beginning and after that you run just mongod without specifying dbpath ?
              – ler
              Dec 15 '17 at 16:27















            1














            mongod --port portnumber --dbpath /path_to_your_folder


            By default portnumber is 27017 and path is /var/lib/mongodb



            You can set your own port number and path where you want to keep all your database.






            share|improve this answer






















            • does it needs to set dbpath every time you run the mongod or just once at the beginning and after that you run just mongod without specifying dbpath ?
              – ler
              Dec 15 '17 at 16:27













            1












            1








            1






            mongod --port portnumber --dbpath /path_to_your_folder


            By default portnumber is 27017 and path is /var/lib/mongodb



            You can set your own port number and path where you want to keep all your database.






            share|improve this answer














            mongod --port portnumber --dbpath /path_to_your_folder


            By default portnumber is 27017 and path is /var/lib/mongodb



            You can set your own port number and path where you want to keep all your database.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jun 8 '17 at 10:57









            Bugs

            4,14992536




            4,14992536










            answered May 26 '17 at 12:16









            aaditya

            134414




            134414











            • does it needs to set dbpath every time you run the mongod or just once at the beginning and after that you run just mongod without specifying dbpath ?
              – ler
              Dec 15 '17 at 16:27
















            • does it needs to set dbpath every time you run the mongod or just once at the beginning and after that you run just mongod without specifying dbpath ?
              – ler
              Dec 15 '17 at 16:27















            does it needs to set dbpath every time you run the mongod or just once at the beginning and after that you run just mongod without specifying dbpath ?
            – ler
            Dec 15 '17 at 16:27




            does it needs to set dbpath every time you run the mongod or just once at the beginning and after that you run just mongod without specifying dbpath ?
            – ler
            Dec 15 '17 at 16:27











            0














            very simple:



            sudo chown mongodb:mongodb /var/lib/mongodb/mongod.lock 





            share|improve this answer


















            • 2




              Perhaps it would be of benefit if you give a bit of an explanation as this has been flagged as low qualify.
              – Gerhard Barnard
              Nov 12 at 11:03










            • at the first when the problem is occurring I deleted mongod. lock sudo rm /var/lib/mongodb/mongod.lock after that I launched it with sudo mongod --dbpath=/var/lib/mongodb but I am obliged to run it every time but I observed that mongod. lock was re-created and the owner is root and not mongodb
              – Mezlini
              Nov 13 at 16:50















            0














            very simple:



            sudo chown mongodb:mongodb /var/lib/mongodb/mongod.lock 





            share|improve this answer


















            • 2




              Perhaps it would be of benefit if you give a bit of an explanation as this has been flagged as low qualify.
              – Gerhard Barnard
              Nov 12 at 11:03










            • at the first when the problem is occurring I deleted mongod. lock sudo rm /var/lib/mongodb/mongod.lock after that I launched it with sudo mongod --dbpath=/var/lib/mongodb but I am obliged to run it every time but I observed that mongod. lock was re-created and the owner is root and not mongodb
              – Mezlini
              Nov 13 at 16:50













            0












            0








            0






            very simple:



            sudo chown mongodb:mongodb /var/lib/mongodb/mongod.lock 





            share|improve this answer














            very simple:



            sudo chown mongodb:mongodb /var/lib/mongodb/mongod.lock 






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 12 at 10:07









            Vineeth Sai

            2,38641123




            2,38641123










            answered Nov 12 at 9:47









            Mezlini

            167




            167







            • 2




              Perhaps it would be of benefit if you give a bit of an explanation as this has been flagged as low qualify.
              – Gerhard Barnard
              Nov 12 at 11:03










            • at the first when the problem is occurring I deleted mongod. lock sudo rm /var/lib/mongodb/mongod.lock after that I launched it with sudo mongod --dbpath=/var/lib/mongodb but I am obliged to run it every time but I observed that mongod. lock was re-created and the owner is root and not mongodb
              – Mezlini
              Nov 13 at 16:50












            • 2




              Perhaps it would be of benefit if you give a bit of an explanation as this has been flagged as low qualify.
              – Gerhard Barnard
              Nov 12 at 11:03










            • at the first when the problem is occurring I deleted mongod. lock sudo rm /var/lib/mongodb/mongod.lock after that I launched it with sudo mongod --dbpath=/var/lib/mongodb but I am obliged to run it every time but I observed that mongod. lock was re-created and the owner is root and not mongodb
              – Mezlini
              Nov 13 at 16:50







            2




            2




            Perhaps it would be of benefit if you give a bit of an explanation as this has been flagged as low qualify.
            – Gerhard Barnard
            Nov 12 at 11:03




            Perhaps it would be of benefit if you give a bit of an explanation as this has been flagged as low qualify.
            – Gerhard Barnard
            Nov 12 at 11:03












            at the first when the problem is occurring I deleted mongod. lock sudo rm /var/lib/mongodb/mongod.lock after that I launched it with sudo mongod --dbpath=/var/lib/mongodb but I am obliged to run it every time but I observed that mongod. lock was re-created and the owner is root and not mongodb
            – Mezlini
            Nov 13 at 16:50




            at the first when the problem is occurring I deleted mongod. lock sudo rm /var/lib/mongodb/mongod.lock after that I launched it with sudo mongod --dbpath=/var/lib/mongodb but I am obliged to run it every time but I observed that mongod. lock was re-created and the owner is root and not mongodb
            – Mezlini
            Nov 13 at 16:50

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21448268%2fhow-to-set-mongod-dbpath%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3

            Museum of Modern and Contemporary Art of Trento and Rovereto