我在Google Compute Engine实例上有一个KeystoneJS应用,在我的项目文件夹中执行mongod和npm start之后,我运行gcloud app deploy并得到以下错误:
Mongoose connection "error" event fired with:
{ MongoError: failed to connect to server [localhost:27017] on first connect
at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:326:35)
at Pool.emit (events.js:182:13)
at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:272:12)
at Object.onceWrapper (events.js:273:13)
at Connection.emit (events.js:182:13)
at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:175:49)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
name: 'MongoError',
message:
'failed to connect to server [localhost:27017] on first connect' }
Error: KeystoneJS (Modern Marketing) failed to start - Check that you are running `mongod` in a separate process.
at NativeConnection.<anonymous> (/app/node_modules/keystone/lib/core/openDatabaseConnection.js:59:10)
at NativeConnection.emit (events.js:182:13)
at Immediate.<anonymous> (/app/node_modules/mongoose/lib/connection.js:296:19)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! modern-marketing@0.0.0 start: `node keystone.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the modern-marketing@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-01-02T05_59_39_493Z-debug.log
我在MongoDB或KeystoneJS方面经验不足,因此非常感谢
答案 0 :(得分:0)
似乎在部署到GAE时,您保留了到本地托管mongo数据库的默认连接。 (failed to connect to server [localhost:27017]
)
由于GAE环境中没有运行mongodb,因此您必须创建一个mongo数据库(您可以在此处使用许多不同的mongodb服务),并使用MONGO_URI
env变量来设置项目。
Keystonejs然后将尝试连接您在此变量中设置的数据库。
我希望此评论对您有帮助,如果您在设置所有内容时仍然遇到问题,可以向我们展示您的app.yaml文件;)