2013-12-17 34 views
0

因此,我在本地windows安裝中連接到MongoDB時遇到了很多問題。最終,MongoClient.Connect函數執行我的回調函數(可能在我稱之爲20秒後),並且它只會失敗並帶來非常無用的錯誤:mongo connect error通過nodejs連接到本地mongodb不起作用

我已經在下面包含了相關代碼......希望它足夠小讓我的觀點貫穿始終。

config = require '../../config.json' 
databaseEngine = config.storage #this is 'mongo' 

Database = if databaseEngine is 'mongo' then require('mongodb').MongoClient else require 'nedb' 

class ModuleDatabase 

    load:() => 
     if not @label?.length then throw new Error "Database must have a name." 
     if not @root?.length then throw new Error "Module must have a shortName of length 1 or greater." 

     if databaseEngine is 'mongo' 

      if not ModuleDatabase::databaseConnection 
       Database.connect "mongodb://localhost:28017/kurea", {server:{auto_reconnect:true}}, (e, db) => 
        console.log 'mongo!' 
        throw e if e? 

        ModuleDatabase::databaseConnection = db 

        @db = ModuleDatabase::databaseConnection.collection "#{@root}_#{@label}" 
      else 
       @db = ModuleDatabase::databaseConnection.collection "#{@root}_#{@label}" 
+0

'err'的內容是什麼?將其記錄到控制檯,而不是僅僅投擲它。 – Nate

+0

我感到超級尷尬,但它看起來像我一直有錯誤的端口。我不知道它是如何滑出我的想法來嘗試/捕獲該代碼塊。謝謝。 – Seiyria

回答

0

爲了記錄在案,端口28107(或mongodbs端口+ 1000)是診斷端口,並且不能實際使用與數據庫進行交互。誰知道?

+0

僅供參考,在MongoDB手冊中有一個[默認端口](http://docs.mongodb.org/manual/reference/default-mongodb-port/)的列表:) – Stennie

+0

感謝那一點信息!是的,對MySQL/MariaDB最熟悉,我知道他們只在一個數據庫端口上運行,並沒有診斷程序。因此,我在命令行中看到了第一個。 – Seiyria