我已经成功地在Google App Engine上部署了一个自定义的Node.js应用程序。然而,当尝试连接时,mongoose超时导致无法启动该应用程序。令人沮丧的是,使用完全相同的参数在我的本地机器上可以正常连接mongoose。
我的MongoDb URI的格式为:
作为URI所示,该数据库由mlab托管。它是Google Cloud Platform上的沙盒实例。但是我没有使用Google Compute Engine部署数据库。当我通过mlab的设置过程时,我只选择在GCP上进行托管。
我在SO上遇到了类似的问题,但其中大多数都没有被接受的答案。只有一些不同的评论,没有被接受的解决方案。
因此,我的问题是,在尝试连接上述URI时,我的App Engine实例和本地计算机之间有什么区别?我选择让mlab在GCP上托管它是否重要?如果我选择让它托管在Amazon AWS上,会有什么不同?问题的根本原因是什么?
供参考,以下是我找到的类似问题:
我的MongoDb URI的格式为:
mongodb://<dbuser>:<dbpassword>@xxxx.mlab.com:<portNumber>/db-name
作为URI所示,该数据库由mlab托管。它是Google Cloud Platform上的沙盒实例。但是我没有使用Google Compute Engine部署数据库。当我通过mlab的设置过程时,我只选择在GCP上进行托管。
我在SO上遇到了类似的问题,但其中大多数都没有被接受的答案。只有一些不同的评论,没有被接受的解决方案。
因此,我的问题是,在尝试连接上述URI时,我的App Engine实例和本地计算机之间有什么区别?我选择让mlab在GCP上托管它是否重要?如果我选择让它托管在Amazon AWS上,会有什么不同?问题的根本原因是什么?
供参考,以下是我找到的类似问题:
此外,如果有帮助的话,mongodb被用作业务模型的数据库,是应用程序Express Session的数据存储和socket.io中瞬态数据的存储。
部署后来自应用引擎的错误堆栈跟踪:
2017-10-18 02:13:46 default[20171017t215757] npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
2017-10-18 02:13:46 default[20171017t215757] npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
2017-10-18 02:13:46 default[20171017t215757] npm ERR! enoent This is most likely not a problem with npm itself
2017-10-18 02:13:46 default[20171017t215757] npm ERR! enoent and is related to npm not being able to find a file.
2017-10-18 02:13:46 default[20171017t215757] npm ERR! enoent
2017-10-18 02:13:46 default[20171017t215757]
2017-10-18 02:13:46 default[20171017t215757] npm ERR! Please include the following file with any support request:
2017-10-18 02:13:46 default[20171017t215757] npm ERR! /app/npm-debug.log
2017-10-18 02:23:41 default[20171017t215757] npm ERR! Linux 3.16.0-4-amd64
2017-10-18 02:23:41 default[20171017t215757] npm ERR! argv "/nodejs/bin/node" "/nodejs/bin/npm" "start"
2017-10-18 02:23:41 default[20171017t215757] npm ERR! node v6.11.3
2017-10-18 02:23:41 default[20171017t215757] npm ERR! npm v3.10.10
2017-10-18 02:23:41 default[20171017t215757] npm ERR! path /app/package.json
2017-10-18 02:23:41 default[20171017t215757] npm ERR! code ENOENT
2017-10-18 02:23:41 default[20171017t215757] npm ERR! errno -2
2017-10-18 02:23:41 default[20171017t215757] npm ERR! syscall open
在Google Cloud Shell本地运行应用时的错误堆栈跟踪:
/home/myuser/src/project-id/teammate-express-server/node_modules/mongodb/lib/mongo_client.js:421
throw err
^
MongoError: failed to connect to server [ds147454.mlab.com:47454] on first connect [MongoError: connection 1 to ds147454.mlab.com:47454 timed out]
at Pool.<anonymous> (/home/myuser/src/project-id/teammate-express-server/node_modules/mongodb-core/lib/topologies/server.js:336:35)
at emitOne (events.js:96:13)
at Pool.emit (events.js:188:7)
at Connection.<anonymous> (/home/myuser/src/project-id/teammate-express-server/node_modules/mongodb-core/lib/connection/pool.js:280:12)
at Connection.g (events.js:292:16)
at emitTwo (events.js:106:13)
at Connection.emit (events.js:191:7)
at Socket.<anonymous> (/home/myuser/src/project-id/teammate-express-server/node_modules/mongodb-core/lib/connection/connection.js:197:10)
at Socket.g (events.js:292:16)
at emitNone (events.js:86:13)
at Socket.emit (events.js:185:7)
at Socket._onTimeout (net.js:338:8)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)