【发布时间】:2017-05-06 16:38:55
【问题描述】:
我正在使用 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 变量。稍后我们将 cloudant 资源称为 ReST API。我在这里有点困惑,不认为我们需要做任何密切的联系(这实际上意味着除了使 cloudant 变量无效之外什么都没有)。可以请分享任何cmets,无论我是对还是错?提前致谢。
【问题讨论】:
标签: node.js cloudant dbconnection