我是Node.js的新手。所以我尝试使用parse-example将我的Node.js应用程序与Mongo DB连接起来。因此,在我安装完所有内容后,更改了Master和AppID(在Index.js和script.js中),我尝试启动我的应用程序(npm start),然后出现这些警告。
> > parse-server-example@1.4.0 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
结果是我无法使用错误500内部服务器错误连接到我的Mongo数据库。
答案 0 :(得分:0)
当然,在你没有提供的代码中发现问题是猜测工作,但我认为从错误消息中可以明显看出你没有监听localhost:27017的Mongo数据库。
答案 1 :(得分:0)
您没有提供数据库连接字符串(DATABASE_URI),因此服务器正在尝试连接到localhost。你在哪里托管你的MongoDB,你在哪里托管你的服务器?
在index.js文件中,您需要包含数据库连接字符串:
var databaseUri = mongodb://...;
希望有所帮助。