2013-05-15 79 views
0

我通過自制軟件安裝了mongodb,並遇到一些試圖連接數據庫的問題。如何讓我的應用程序連接到mongo db?

當我的mongod在終端上鍵入啓動服務器,一切似乎都很正常工作:然而,

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

,當我嘗試使用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]] 

還包括啓動服務器,我嘗試在新的終端標籤運行蒙戈和我碰到下面的錯誤後:

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 

我還包括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 

我有這個設置,而且對我的iMac電腦工作正常,但似乎無法得到它的工作在我的全新的MacBook。我怎樣才能解決這個問題?

+0

您是否嘗試過使用[mongoose](https://npmjs.org/package/mongoose)模塊? – dmahapatro

+0

@dmahapatro是的,我實際上使用貓鼬。但是我相信這個問題是由於mongob從這個問題中解決出來的。 – Scott

+1

看起來您沒有訪問'/ usr/local/var/mongodb/admin.ns'的權限。然後它終止。你有沒有檢查你的許可?你能改變你的權限嗎? – dmahapatro

回答

3

您需要更改您的db文件夾的權限:/usr/local/var/mongodb/,或使用sudo運行mongod。

+0

謝謝,不得不走出去。我一回來就會嘗試這個嘗試 – Scott

相關問題