因此,我在本地windows安裝中連接到MongoDB時遇到了很多問題。最終,MongoClient.Connect函數執行我的回調函數(可能在我稱之爲20秒後),並且它只會失敗並帶來非常無用的錯誤:通過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}"
'err'的內容是什麼?將其記錄到控制檯,而不是僅僅投擲它。 – Nate
我感到超級尷尬,但它看起來像我一直有錯誤的端口。我不知道它是如何滑出我的想法來嘗試/捕獲該代碼塊。謝謝。 – Seiyria