简体   繁体   English

如何获得我的应用程序以连接到mongo db?

[英]How can I get my app to connect to mongo db?

I installed mongodb via homebrew and and running into some problems trying to connect to the database. 我通过自制软件安装了mongodb,并在尝试连接数据库时遇到了一些问题。

When I type in mongod in the terminal to start the server, everything appears to be working fine: 当我在终端中键入mongod来启动服务器时,一切似乎工作正常:

new-host-4:~ scotty$ mongod
all output going to: /usr/local/var/log/mongodb/mongo.log

however, when I try to start the server using nodemon I get the following error: 但是,当我尝试使用nodemon启动服务器时,出现以下错误:

new-host-4:App scotty$ nodemon server.js
15 May 12:25:23 - [nodemon] v0.7.8
15 May 12:25:23 - [nodemon] to restart at any time, enter `rs`
15 May 12:25:23 - [nodemon] watching: /Users/scotty/Documents/web_apps/App
15 May 12:25:23 - [nodemon] starting `node server.js`
   info  - socket.io started
connection error: [Error: failed to connect to [localhost:27017]]

Also after starting the server, I try running mongo in a new terminal tab and I get the following error: 另外,在启动服务器后,我尝试在新的终端选项卡中运行mongo,并且出现以下错误:

new-host-4:~ scotty$ mongo
MongoDB shell version: 2.4.3
connecting to: test
Wed May 15 12:28:11.123 JavaScript execution failed: Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112
exception: connect failed

I'm also including the mongolog: 我还包括mongolog:

***** SERVER RESTARTED *****


Wed May 15 12:30:37.624 [initandlisten] MongoDB starting : pid=3834 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=new-host-4.home
Wed May 15 12:30:37.625 [initandlisten] 
Wed May 15 12:30:37.625 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Wed May 15 12:30:37.625 [initandlisten] db version v2.4.3
Wed May 15 12:30:37.625 [initandlisten] git version: fe1743177a5ea03e91e0052fb5e2cb2945f6d95f
Wed May 15 12:30:37.625 [initandlisten] build info: Darwin bs-osx-106-x86-64-1.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun  7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_49
Wed May 15 12:30:37.625 [initandlisten] allocator: system
Wed May 15 12:30:37.625 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb", logappend: "true", logpath: "/usr/local/var/log/mongodb/mongo.log" }
Wed May 15 12:30:37.625 [initandlisten] journal dir=/usr/local/var/mongodb/journal
Wed May 15 12:30:37.625 [initandlisten] recover : no journal files present, no recovery needed
Wed May 15 12:30:37.641 [initandlisten] couldn't open /usr/local/var/mongodb/admin.ns errno:13 Permission denied
Wed May 15 12:30:37.641 [initandlisten] error couldn't open file /usr/local/var/mongodb/admin.ns terminating
Wed May 15 12:30:37.641 dbexit: 
Wed May 15 12:30:37.641 [initandlisten] shutdown: going to close listening sockets...
Wed May 15 12:30:37.641 [initandlisten] shutdown: going to flush diaglog...
Wed May 15 12:30:37.641 [initandlisten] shutdown: going to close sockets...
Wed May 15 12:30:37.641 [initandlisten] shutdown: waiting for fs preallocator...
Wed May 15 12:30:37.641 [initandlisten] shutdown: lock for final commit...
Wed May 15 12:30:37.641 [initandlisten] shutdown: final commit...
Wed May 15 12:30:37.642 [initandlisten] shutdown: closing all files...
Wed May 15 12:30:37.642 [initandlisten] closeAllFiles() finished
Wed May 15 12:30:37.642 [initandlisten] journalCleanup...
Wed May 15 12:30:37.642 [initandlisten] removeJournalFiles
Wed May 15 12:30:37.642 [initandlisten] shutdown: removing fs lock...
Wed May 15 12:30:37.642 dbexit: really exiting now

I had this set up and working fine on my iMac but can't seem to get it working on my new macbook. 我已经进行了此设置,并且可以在iMac上正常工作,但是似乎无法在新的Macbook上运行它。 How can I get this fixed? 如何解决此问题?

您需要更改对db文件夹的权限: /usr/local/var/mongodb/ ,或者使用sudo运行mongod。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM