gpt4 book ai didi

node.js - 如何限制 monk Node.js 中的连接池大小

转载 作者:行者123 更新时间:2023-12-05 07:55:12 27 4
gpt4 key购买 nike

我正在使用 monk 模块从 mongodb 获取数据。但是一旦我连接到数据库,它就会创建 5 个连接。

这是我的命令行 mongodb 服务器控制台...

 2015-05-14T10:32:35.618+0530 I NETWORK  [initandlisten] connection accepted from
127.0.0.1:61015 #3 (2 connections now open)
2015-05-14T10:32:35.619+0530 I NETWORK [initandlisten] connection accepted from
127.0.0.1:61016 #4 (3 connections now open)
2015-05-14T10:32:35.621+0530 I NETWORK [initandlisten] connection accepted from
127.0.0.1:61017 #5 (4 connections now open)
2015-05-14T10:32:35.621+0530 I NETWORK [initandlisten] connection accepted from
127.0.0.1:61018 #6 (5 connections now open)
2015-05-14T10:32:35.622+0530 I NETWORK [initandlisten] connection accepted from
127.0.0.1:61019 #7 (6 connections now open)
2015-05-14T10:32:35.629+0530 I NETWORK [conn3] end connection 127.0.0.1:61015 (
5 connections now open)
2015-05-14T10:32:35.629+0530 I NETWORK [conn4] end connection 127.0.0.1:61016 (
5 connections now open)
2015-05-14T10:32:35.629+0530 I NETWORK [conn5] end connection 127.0.0.1:61017 (
5 connections now open)
2015-05-14T10:32:35.629+0530 I NETWORK [conn6] end connection 127.0.0.1:61018 (
5 connections now open)
2015-05-14T10:32:35.629+0530 I NETWORK [conn7] end connection 127.0.0.1:61019 (
5 connections now open)

最佳答案

设置monk连接池大小如下:

const monk = require('monk');
const db = monk('localhost/mydb', {
poolSize: 7 // number of connections
});

默认为 5

来源:https://automattic.github.io/monk/docs/manager/

关于node.js - 如何限制 monk Node.js 中的连接池大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30229615/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com