所以我在本地Windows安装上连接到MongoDB时遇到很多问题。最终,MongoClient.Connect函数执行我的回调(可能在我调用它之后20秒),它只是失败并且出现了一个非常无用的错误:
我已经在下方提供了相关代码...希望它足够小,能够明确我的观点。
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 :(得分:0)
对于记录,端口28107(或mongodbs端口+ 1000)是诊断端口,您实际上无法使用它来与数据库连接。谁知道?