我在项目的最顶层目录中运行node server.js
:
这就是我得到的错误:
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
The magic happens on port 8080
events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [your_database_here:27017]
at null.<anonymous> (/home/ajay/Desktop/easy-node-authentication-facebook/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:549:74)
at emit (events.js:106:17)
at null.<anonymous> (/home/ajay/Desktop/easy-node-authentication-facebook/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:150:15)
at emit (events.js:98:17)
at Socket.<anonymous> (/home/ajay/Desktop/easy-node-authentication-facebook/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:533:10)
at Socket.emit (events.js:95:17)
at net.js:833:16
at process._tickCallback (node.js:419:13)
我已安装mongodb
,当我在浏览器中打开localhost:27017
时,它会显示It looks like you are trying to access MongoDB over HTTP on the native driver port.
。确切的错误在哪里?
答案 0 :(得分:2)
我建议你使用&#39; mongoose&#39;从节点连接mongodb。以下是执行此操作的示例代码。
var mongoose=require('mongoose'),
db = 'mongodb://localhost/test';
mongoose.connect(db);
//and your code goes here
&#13;
您必须安装节点模块&#39; mongoose&#39;。阅读mongoose的文档。