0

I am using MongoDB on OSX. I am following along with a book.

MongoDB: The Definitive Guide, Second Edition

I have MongoDB installed and running. I have made a few collections with some values in them.

I installed using Homebrew

When I run mongo in the terminal my shell starts and I can use it fine.

When I run mongod I get an error stating a do not have a data/db directory. I know this is because the default location for mongo to store data is inside that directory but homebrew sets its own path up.

When I run

Home:~ ThisIsMe$ mongo
MongoDB shell version: 2.6.3
connecting to: test
> db.serverCmdLineOpts()
{
    "argv" : [
        "/usr/local/opt/mongodb/bin/mongod",
        "--config",
        "/usr/local/etc/mongod.conf"
    ],
    "parsed" : {
        "config" : "/usr/local/etc/mongod.conf",
        "net" : {
            "bindIp" : "127.0.0.1"
        },
        "storage" : {
            "dbPath" : "/usr/local/var/mongodb"
        },
        "systemLog" : {
            "destination" : "file",
            "logAppend" : true,
            "path" : "/usr/local/var/log/mongodb/mongo.log"
        }
    },
    "ok" : 1
}
> 

I get those file paths where homebrew set my mongo up at.

I want to make sure everything is set up correctly. Do I need to add something else to be able to run mongod without errors? I am under the impression I should be able to run mongod then go to http://localhost:28017/ to see information about my mongo.

But I cannot get mongod to run without the errors about data/db

Home:~ ThisIsMe$ mongod
mongod --help for help and startup options
2014-07-24T13:09:07.817-0500 [initandlisten] MongoDB starting : pid=1668 port=27017 dbpath=/data/db 64-bit host=NichoDiaz
2014-07-24T13:09:07.817-0500 [initandlisten] 
2014-07-24T13:09:07.817-0500 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2014-07-24T13:09:07.817-0500 [initandlisten] db version v2.6.3
2014-07-24T13:09:07.817-0500 [initandlisten] git version: nogitversion
2014-07-24T13:09:07.817-0500 [initandlisten] build info: Darwin minimavericks.local 13.2.0 Darwin Kernel Version 13.2.0: Thu Apr 17 23:03:13 PDT 2014; root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
2014-07-24T13:09:07.818-0500 [initandlisten] allocator: tcmalloc
2014-07-24T13:09:07.818-0500 [initandlisten] options: {}
2014-07-24T13:09:07.818-0500 [initandlisten] exception in initAndListen: 10296 
*********************************************************************
 ERROR: dbpath (/data/db) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
2014-07-24T13:09:07.818-0500 [initandlisten] dbexit: 
2014-07-24T13:09:07.818-0500 [initandlisten] shutdown: going to close listening sockets...
2014-07-24T13:09:07.818-0500 [initandlisten] shutdown: going to flush diaglog...
2014-07-24T13:09:07.818-0500 [initandlisten] shutdown: going to close sockets...
2014-07-24T13:09:07.818-0500 [initandlisten] shutdown: waiting for fs preallocator...
2014-07-24T13:09:07.818-0500 [initandlisten] shutdown: lock for final commit...
2014-07-24T13:09:07.818-0500 [initandlisten] shutdown: final commit...
2014-07-24T13:09:07.818-0500 [initandlisten] shutdown: closing all files...
2014-07-24T13:09:07.818-0500 [initandlisten] closeAllFiles() finished
2014-07-24T13:09:07.818-0500 [initandlisten] dbexit: really exiting now
Home:~ ThisIsMe$ 
wuno
  • 9,547
  • 19
  • 96
  • 180

1 Answers1

1

It's there in the error message:

ERROR: dbpath (/data/db) does not exist. 
Create this directory or give existing directory in --dbpath.

You need to create the /data and /data/db directories and make certain that the user running mongod can write to both of those directories. That's where mongod is going to write your database data. It's not created by default. Alternatively you could create your data directory elsewhere and then pass it in using --dbpath.

John Petrone
  • 26,943
  • 6
  • 63
  • 68
  • what is the difference between creating the dir data and data/db because the dir db does not appear to be necessary anywhere but it complains about it if you dont have data – wuno Jul 24 '14 at 19:24
  • It's just the default directory layout - /data and then a db directory underneath it - you can create any structure you want but if it's not /data/db you need to let mongodb know using --dbpath – John Petrone Jul 24 '14 at 19:30
  • As long as I do, mongod --dbpath data it works fine. It does not make me add db. But when I dont specify that path with each time I run in says I need the data/db – wuno Jul 24 '14 at 21:32
  • Yes, that's because that's the default - the default dbpath is /data/db - if you do not set --dbpath it will look for it every time. – John Petrone Jul 24 '14 at 21:36