2016-11-21 147 views
0

我是Node.js的新手。所以我尝试了parse-example将我的Node.js应用程序与Mongo DB连接起来。所以在我安装了所有东西之后,改变了Master和AppID(在Index.js和script.js中),我尝试启动我的应用程序(npm start),然后出现这些警告。Node.js无法连接到Mongo DB

>  > [email protected] start C:\Users\TAASCTI5\temp\parseex\parse-server-e 
>  xample 
>  > node index.js 
>  
>  DATABASE_URI not specified, falling back to localhost. 
>  parse-server-example running on port 1337. 
>  info: Parse LiveQuery Server starts running 
>  warn: Unable to ensure uniqueness for usernames: MongoError: failed to connect 
>  to server [localhost:27017] on first connect 
>   at Pool.<anonymous> (C:\Users\TAASCTI5\temp\parseex\parse-server-example\nod 
>  e_modules\parse-server\node_modules\mongodb-core\lib\topologies\server.js:313:35 
> ) 
>   at emitOne (events.js:96:13) 
>   at Pool.emit (events.js:188:7) 
>   at Connection.<anonymous> (C:\Users\TAASCTI5\temp\parseex\parse-server-examp 
>  le\node_modules\parse-server\node_modules\mongodb-core\lib\connection\pool.js:26 
>  0:12) 
>   at Connection.g (events.js:291:16) 
>   at emitTwo (events.js:106:13) 
>   at Connection.emit (events.js:191:7) 
>   at Socket.<anonymous> (C:\Users\TAASCTI5\temp\parseex\parse-server-example\n 
>  ode_modules\parse-server\node_modules\mongodb-core\lib\connection\connection.js: 
>  162:49) 
>   at Socket.g (events.js:291:16) 
>   at emitOne (events.js:96:13) 
>  warn: Unable to ensure uniqueness for user email addresses: MongoError: failed 
>  to connect to server [localhost:27017] on first connect 
>   at Pool.<anonymous> (C:\Users\TAASCTI5\temp\parseex\parse-server-example\nod 
>  e_modules\parse-server\node_modules\mongodb-core\lib\topologies\server.js:313:35 
> ) 
>   at emitOne (events.js:96:13) 
>   at Pool.emit (events.js:188:7) 
>   at Connection.<anonymous> (C:\Users\TAASCTI5\temp\parseex\parse-server-examp 
>  le\node_modules\parse-server\node_modules\mongodb-core\lib\connection\pool.js:26 
>  0:12) 
>   at Connection.g (events.js:291:16) 
>   at emitTwo (events.js:106:13) 
>   at Connection.emit (events.js:191:7) 
>   at Socket.<anonymous> (C:\Users\TAASCTI5\temp\parseex\parse-server-example\n 
>  ode_modules\parse-server\node_modules\mongodb-core\lib\connection\connection.js: 
>  162:49) 
>   at Socket.g (events.js:291:16) 
>   at emitOne (events.js:96:13) 
>  (node:18132) UnhandledPromiseRejectionWarning: Unhandled promise rejection (reje 
>  ction id: 4): MongoError: failed to connect to server [localhost:27017] on first 
>  connect 
>  (node:18132) UnhandledPromiseRejectionWarning: Unhandled promise rejection (reje 
>  ction id: 5): MongoError: failed to connect to server [localhost:27017] on first 
>  connect 

结果是我无法连接到我的Mongo DB,出现错误500内部服务器错误。

+0

你需要发布你的代码......但是看起来你没有在你的计算机上本地运行mongodb。它可能已安装,但可能未运行。 – Randy

回答

0

您没有提供数据库连接字符串(DATABASE_URI),因此服务器正尝试连接到本地主机。你在哪里托管你的MongoDB,你在哪里托管你的服务器?

在你index.js文件,你需要包括你的数据库连接字符串:

var databaseUri = mongodb://...; 

希望有所帮助。

+0

它的作品知道,谢谢你,我的朋友。 –

0

当然,在您没有提供的代码中发现问题是一种猜测工作,但我认为从错误消息中可以明显看出,您没有在localhost上监听Mongo数据库:27017。