设置并运行MongoDB

时间:2014-07-24 18:10:51

标签: mongodb

我在OSX上使用MongoDB。我跟着一本书。

MongoDB: The Definitive Guide, Second Edition

我已安装并运行MongoDB。我已经制作了一些collections,其中包含一些values

我使用Homebrew

安装

当我在终端中运行mongo时,我的shell启动了,我可以正常使用它。

当我运行mongod时,我收到一条错误消息,指出没有数据/ db目录。我知道这是因为mongo存储数据的默认位置在该目录中,但homebrew设置了自己的路径。

当我跑步时

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
}
> 

我得到homebrew设置我的mongo的文件路径。

我想确保一切设置正确。我是否需要添加其他内容才能正常运行mongod?我的印象是我应该能够运行mongod,然后转到http://localhost:28017/查看有关我的mongo的信息。

但我无法让mongod在没有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$ 

1 个答案:

答案 0 :(得分:1)

它出现在错误消息中:

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

您需要创建/ data和/ data / db目录,并确保运行mongod的用户可以写入这两个目录。这就是mongod要编写数据库数据的地方。它不是默认创建的。或者,您可以在其他位置创建数据目录,然后使用--dbpath。

传递它
相关问题