我使用nodejs中的" cloudant“模块连接到cloudant (npm install --save cloudant)。下面是初始化db连接变量并使用它的代码。
//instantiate a cloudant var with the cloudant url. The url has id, password in it.
cloudant = require('cloudant')(dbCredentials.url);
//set the middleware with the db name
db = cloudant.use(dbCredentials.dbName);
//use the db variable to insert data into the db
function(req){
db.insert({
name:req.name,
age:req.age
},id,function(err,doc){
....
});
};在我使用db变量后,我应该担心关闭连接吗?这对我来说没有任何意义,因为我们在这里没有使用任何连接池。对我来说,我们只是使用端点、凭据和db名称来实例化db变量。稍后,我们将作为ReST API调用cloudant资源。我在这里有点困惑,不认为我们需要做任何紧密的连接(这实际上意味着除了将cloudant变量置为空之外,什么也不是)。请分享我的意见,不管我是错是对?提前谢谢。
发布于 2016-12-21 17:57:17
默认情况下,Cloudant库使用默认的Node.js连接池,因此它将遵循服务器的"Keep-Alive“指令,但您无需担心。只需继续调用Cloudant库函数,库就会在需要时建立HTTP连接-必要时重用现有连接,在其他情况下创建新连接。
https://stackoverflow.com/questions/41259672
复制相似问题