在 keystonejs 应用程序中关闭了 Mongo 连接 [英] Mongo connection closed in keystonejs app

查看:54
本文介绍了在 keystonejs 应用程序中关闭了 Mongo 连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的 keystonejs 项目,我创建了两个 docker 容器(一个用于 mongo,一个用于 keystonejs 应用程序).一切正常,除了我在浏览网站时经常遇到连接关闭"错误(通常是在我没有导航几分钟的情况下).完整的错误堆栈如下:

For my keystonejs project I have created two docker containers (one for mongo, one for the keystonejs app). All works well, with the exception that I am getting very often a "connection closed" error when browsing the site (usually when I haven't navigated for a couple of minutes). The full error stack is below:

Error thrown for request: /blog
Error: connection closed
    at null.<anonymous> (/usr/src/app/node_modules/keystone/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:618:45)
    at emitNone (events.js:67:13)
    at emit (events.js:166:7)
    at null.<anonymous> (/usr/src/app/node_modules/keystone/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:171:15)
    at emitTwo (events.js:87:13)
    at emit (events.js:172:7)
    at Socket.<anonymous> (/usr/src/app/node_modules/keystone/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:550:12)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at TCP._onclose (net.js:477:12)

我做了一些调查,stackoverflow 上的另一篇文章建议在 mongoose 上使用 keepAlive 选项(猫鼬输出错误错误:连接关闭").但是,我不知道如何在 keystonejs 中使用这些选项.有人可以帮忙吗?

I have done some investigation, and another post on stackoverflow suggest to use the keepAlive option on mongoose (mongoose output the error "Error: connection closed"). However, I have no idea how I can use these options in keystonejs. Can anybody help?

最好的问候,汤姆

推荐答案

我是这样工作的:

var mongoose = require('mongoose');

mongoose.set('server', {
        socketOptions: {
            keepAlive: 1
        }});

keystone.set('mongoose', mongoose);

干杯,汤姆

这篇关于在 keystonejs 应用程序中关闭了 Mongo 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆