连接错误 (err) - Mongodb 在 expressjs 框架中使用 nodejs 的连接
Connection Error (err) - Mongodb connection using nodejs in an expressjs framework
我现在正在接受 nodejs 培训,以及如何使用 nodejs 和 expressjs 作为框架开发 MVC 应用程序。我有一个 TDD 方法以及模型和视图 类 与 TDD 测试脚本一起编写。我有一个 mongodb 测试脚本,它失败并显示以下错误消息:
expressjs_multech_project mul$ jasmine-node ./tests
.......F
Failures:
1) MongoDB is there a server running?
Message:
Expected { } to be null.
Stacktrace:
Error: Expected { } to be null.
at /Users/.../expressjs_multech_project/tests/mongodb.spec.js:6:19
at /Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/mongo_client.js:334:20
at /Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/db.js:258:16
at null.<anonymous> (/Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/connection/server.js:621:7)
at emitThree (events.js:110:13)
at emit (events.js:188:7)
at null.<anonymous> (/Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:139:15)
at emitTwo (events.js:100:13)
Finished in 0.182 seconds
8 tests, 18 assertions, 1 failure, 0 skipped
我将 Jasmine 用于节点作为测试包,所有其他测试仅通过模型和视图 类 编写。我不明白为什么我的 mongodb TDD 脚本在 mongodb 上失败,而当我 npm start
时,它没有开始返回 app.js 错误消息:
> node app.js
Sorry, the server (mongodb) is not running
我回头研究了堆栈跟踪,据我所知,mongodb 没有建立连接,它返回 null。我检查了 mongodb 以确保它在那里:
Johns-MacBook-Pro:expressjs_multech_project mul$ npm list mongodb
multechanalytics@0.0.1 /Users/.../expressjs_multech_project
└── mongodb@1.3.10
我已经尝试了很多补救措施,但迄今为止没有任何效果。关于解决与服务器的连接问题的任何想法,以便我可以继续进行此 expressjs MVC 培训项目?
我的 config/index.js 看起来像这样:
var config = {
local: {
mode: 'local',
port: 3000,
mongo: {
host: '127.0.0.1',
port: 27017
}
},
staging: {
mode: 'staging',
port: 4000,
mongo: {
host: '127.0.0.1',
port: 27017
}
},
production: {
mode: 'production',
port: 5000,
mongo: {
host: '127.0.0.1',
port: 27017
}
}
}
module.exports = function(mode) {
//export module configuration making it available to all files in folder
return config[mode || process.argv[2] || 'local'] || config.local;
这是我将 package.json
文件和 npm install mongodb --save
扩充到 运行 在 npm install
[=20= 之后安装 mongo 时得到的输出]
muls-MacBook-Pro:expressjs_multech_project jmulhall$ npm install mongodb --save
> kerberos@0.0.11 install /Users/jmulhall/Documents/Web_Development/Express-Nodejs/expressjs_multech_project/node_modules/kerberos
> (node-gyp rebuild 2> builderror.log) || (exit 0)
CXX(target) Release/obj.target/kerberos/lib/kerberos.o
> bson@0.2.22 install /Users/jmulhall/Documents/Web_Development/Express-Nodejs/expressjs_multech_project/node_modules/bson
> (node-gyp rebuild 2> builderror.log) || (exit 0)
CXX(target) Release/obj.target/bson/ext/bson.o
multechanalytics@0.0.1 /Users/jmulhall/Documents/Web_Development/Express-Nodejs/expressjs_multech_project
├─┬ less-middleware@0.1.12
│ └─┬ less@1.4.2
│ └─┬ request@2.69.0
│ └─┬ bl@1.0.3
│ └─┬ readable-stream@2.0.6
│ └── isarray@1.0.0
└─┬ mongodb@1.4.40
├─┬ bson@0.2.22
│ └── nan@1.8.4
├── kerberos@0.0.11
└─┬ readable-stream@2.0.6
└── isarray@1.0.0
谢谢...
这看起来不像是安装组件 return exit 0
的错误,这很好。
需要说明的是,您安装的软件包只是官方 mongodb 驱动程序 https://www.npmjs.com/package/mongodb - The official MongoDB driver for Node.js. Provides a high-level API on top of mongodb-core that is meant for end users.
您需要安装 mongodb 服务器才能进行完整安装 https://docs.mongodb.org/manual/installation/
我现在正在接受 nodejs 培训,以及如何使用 nodejs 和 expressjs 作为框架开发 MVC 应用程序。我有一个 TDD 方法以及模型和视图 类 与 TDD 测试脚本一起编写。我有一个 mongodb 测试脚本,它失败并显示以下错误消息:
expressjs_multech_project mul$ jasmine-node ./tests
.......F
Failures:
1) MongoDB is there a server running?
Message:
Expected { } to be null.
Stacktrace:
Error: Expected { } to be null.
at /Users/.../expressjs_multech_project/tests/mongodb.spec.js:6:19
at /Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/mongo_client.js:334:20
at /Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/db.js:258:16
at null.<anonymous> (/Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/connection/server.js:621:7)
at emitThree (events.js:110:13)
at emit (events.js:188:7)
at null.<anonymous> (/Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:139:15)
at emitTwo (events.js:100:13)
Finished in 0.182 seconds
8 tests, 18 assertions, 1 failure, 0 skipped
我将 Jasmine 用于节点作为测试包,所有其他测试仅通过模型和视图 类 编写。我不明白为什么我的 mongodb TDD 脚本在 mongodb 上失败,而当我 npm start
时,它没有开始返回 app.js 错误消息:
> node app.js
Sorry, the server (mongodb) is not running
我回头研究了堆栈跟踪,据我所知,mongodb 没有建立连接,它返回 null。我检查了 mongodb 以确保它在那里:
Johns-MacBook-Pro:expressjs_multech_project mul$ npm list mongodb
multechanalytics@0.0.1 /Users/.../expressjs_multech_project
└── mongodb@1.3.10
我已经尝试了很多补救措施,但迄今为止没有任何效果。关于解决与服务器的连接问题的任何想法,以便我可以继续进行此 expressjs MVC 培训项目?
我的 config/index.js 看起来像这样:
var config = {
local: {
mode: 'local',
port: 3000,
mongo: {
host: '127.0.0.1',
port: 27017
}
},
staging: {
mode: 'staging',
port: 4000,
mongo: {
host: '127.0.0.1',
port: 27017
}
},
production: {
mode: 'production',
port: 5000,
mongo: {
host: '127.0.0.1',
port: 27017
}
}
}
module.exports = function(mode) {
//export module configuration making it available to all files in folder
return config[mode || process.argv[2] || 'local'] || config.local;
这是我将 package.json
文件和 npm install mongodb --save
扩充到 运行 在 npm install
[=20= 之后安装 mongo 时得到的输出]
muls-MacBook-Pro:expressjs_multech_project jmulhall$ npm install mongodb --save
> kerberos@0.0.11 install /Users/jmulhall/Documents/Web_Development/Express-Nodejs/expressjs_multech_project/node_modules/kerberos
> (node-gyp rebuild 2> builderror.log) || (exit 0)
CXX(target) Release/obj.target/kerberos/lib/kerberos.o
> bson@0.2.22 install /Users/jmulhall/Documents/Web_Development/Express-Nodejs/expressjs_multech_project/node_modules/bson
> (node-gyp rebuild 2> builderror.log) || (exit 0)
CXX(target) Release/obj.target/bson/ext/bson.o
multechanalytics@0.0.1 /Users/jmulhall/Documents/Web_Development/Express-Nodejs/expressjs_multech_project
├─┬ less-middleware@0.1.12
│ └─┬ less@1.4.2
│ └─┬ request@2.69.0
│ └─┬ bl@1.0.3
│ └─┬ readable-stream@2.0.6
│ └── isarray@1.0.0
└─┬ mongodb@1.4.40
├─┬ bson@0.2.22
│ └── nan@1.8.4
├── kerberos@0.0.11
└─┬ readable-stream@2.0.6
└── isarray@1.0.0
谢谢...
这看起来不像是安装组件 return exit 0
的错误,这很好。
需要说明的是,您安装的软件包只是官方 mongodb 驱动程序 https://www.npmjs.com/package/mongodb - The official MongoDB driver for Node.js. Provides a high-level API on top of mongodb-core that is meant for end users.
您需要安装 mongodb 服务器才能进行完整安装 https://docs.mongodb.org/manual/installation/