mongo 数据库提前关闭 避免读写任务没有结束,异步任务没有完成,同步指令提前关闭数据库:'MongoError: server instance pool was destroyed'
mongo 数据库提前关闭
// mongodb - npm https://www.npmjs.com/package/mongodb
const mongoCfg = {
uri: 'mongodb://hbaseU:123@192.168.3.103:27017/hbase',
dbName: 'hbase',
collectionName: 'todayUrlsTmpURL'
} const MongoClient = require('mongodb').MongoClient
// npm install assert
const assert = require('assert')
// Use connect method to connect to the server MongoClient.connect(mongoCfg.uri, function (err, client) {
assert.equal(null, err)
console.log('Connected successfully to server')
const db = client.db(mongoCfg.dbName)
const collectionName = mongoCfg.collectionName
findDocuments(db, collectionName, {}, function (docs) {
for (let i in docs) {
const ii = docs[i]
let mgid = ii._id
let filter = {
_id: mgid
}
console.log(filter)
let val = {
$set: {
url: 's'
}
}
updateDocument(db, collectionName, filter, val, function (result) {
console.log(result)
})
}
})
client.close()
}) const findDocuments = function (db, collectionName, filter, callback) {
// Get the documents collection
const collection = db.collection(collectionName)
// Find some documents
collection.find(filter).toArray(function (err, docs) {
assert.equal(err, null)
console.log("Found the following records")
console.log(docs.length)
callback(docs)
})
} const updateDocument = function (db, collectionName, filter, val, callback) {
// Get the documents collection
const collection = db.collection(collectionName)
collection.updateOne(filter, val, function (err, result) {
console.log(err)
assert.equal(err, null)
assert.equal(1, result.result.n)
callback(result)
})
}
// mongodb - npm https://www.npmjs.com/package/mongodb
const mongoCfg = {
uri: 'mongodb://hbaseU:123@192.168.3.103:27017/hbase',
dbName: 'hbase',
collectionName: 'todayUrlsTmpURL'
} const MongoClient = require('mongodb').MongoClient
// npm install assert
const assert = require('assert')
// Use connect method to connect to the server
MongoClient.connect(mongoCfg.uri, function (err, client) {
assert.equal(null, err)
console.log('Connected successfully to server')
const db = client.db(mongoCfg.dbName)
const collectionName = mongoCfg.collectionName
findDocuments(db, collectionName, {}, function (docs) {
for (let i in docs) {
const ii = docs[i]
let mgid = ii._id
let filter = {
_id: mgid
}
console.log(filter)
let val = {
$set: {
url: 'ok-' + mgid
}
}
updateDocument(db, collectionName, filter, val, function (result) {
console.log(result)
})
}
// 在回调中关闭数据库
// 保证读写完全结束后关闭数据库
// 以与之(读写完全结束)同步的方式关闭数据库
client.close()
})
// 避免读写任务没有结束,异步任务没有完成,同步指令提前关闭数据库:'MongoError: server instance pool was destroyed'
// client.close()
}) const findDocuments = function (db, collectionName, filter, callback) {
// Get the documents collection
const collection = db.collection(collectionName)
// Find some documents
collection.find(filter).toArray(function (err, docs) {
assert.equal(err, null)
console.log("Found the following records")
console.log(docs.length)
callback(docs)
})
} const updateDocument = function (db, collectionName, filter, val, callback) {
// Get the documents collection
const collection = db.collection(collectionName)
collection.updateOne(filter, val, function (err, result) {
console.log(err)
assert.equal(err, null)
assert.equal(1, result.result.n)
callback(result)
})
}
mongo 数据库提前关闭 避免读写任务没有结束,异步任务没有完成,同步指令提前关闭数据库:'MongoError: server instance pool was destroyed'的更多相关文章
- 转 查看磁盘IO负载 - 看哪些进程在读写磁盘 以及oracle 异步I/O 和同步I/O
https://www.cnblogs.com/cloudstorage/archive/2012/11/11/2764623.html #####sample 1: Oracle等待事件db fil ...
- spring Batch实现数据库大数据量读写
spring Batch实现数据库大数据量读写 博客分类: spring springBatchquartz定时调度批处理 1. data-source-context.xml <?xml v ...
- MySQL/MariaDB数据库的PROXY实现读写分离
MySQL/MariaDB数据库的PROXY实现读写分离 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.ProxySQL概述 1>.各家互联网公司读写分离的解决方案 m ...
- [转]Visual Studio 2008中如何比较二个数据库的架构【Schema】和数据【Data】并同步
使用场景: 在团队开发中,每一个人都有可能随时更新数据库,这时候数据库中数据和架构等信息都会发生变化.如果更新不及时,就会发生数据错误或数据丢失的风险,影响团队的开发效率和 项目进度,这时候我们该怎么 ...
- Navicat 连接远程数据库报错:1130 - Host "XX.XX.XX.XX" is not allowed to connect to this MySQL server
Navicat 连接远程数据库报错:1130 - Host "XX.XX.XX.XX" is not allowed to connect to this MySQL server ...
- Capistrano:自动完成多台服务器上新版本的同步更新,包括数据库的改变
https://baike.baidu.com/item/Capistrano/6844928?fr=aladdin Capistrano是一种在多台服务器上运行脚本的开源工具,它主要用于部署we ...
- 如果数据库上的row格式是mixed或者mixed的格式,如何对比两台数据库服务器上的数据是否一致呢
如果数据库上的row格式是mixed或者mixed的格式,如何对比两台数据库服务器上的数据是否一致呢
- SQL Server数据库 备份A库,然后删除A库,再还原A库,此时数据库一直显示“正在还原”的解决方法
SQL Server数据库 备份A库,然后删除A库,再还原A库,此时数据库一直显示"正在还原"的解决方法: A库一直显示"正在还原". 在这种状态下,由于未提交 ...
- 一个适合变化的产品部署集成包(nginx+jdk+tomcat+nodejs+mysql+redis+mongo+MYSQL主主(读写分离)集群建立+代码包+持续上线+备份)
一.前言 最近公司做了一套新产品,需要发布到不确定的硬件环境中(不同使用单位规模,使用人数,服务器提供的资源不同)若每次进行人工部署耗时费力,周期过长. 二.分析 具体的部署流程如下: 由上图流程进行 ...
随机推荐
- luogu P1345 [USACO5.4]奶牛的电信Telecowmunication
https://www.luogu.org/problemnew/show/1345 拆点,中间建流量为1的边,跑最小割 #include<cstdio> #include<queu ...
- luogu P1880 石子合并
题目描述 在一个园形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出1个算法,计算出将N堆石子合并成1 ...
- advanced-performance-troubleshooting-waits-latches-spinlocks
https://www.sqlskills.com/blogs/paul/advanced-performance-troubleshooting-waits-latches-spinlocks/
- 列表pagesize修改每页显示的数量失效
◇系统错误修复工具 >> 检测微表正确性 原因是删除一些数据导致记录与实际数据不符 转自:http://bbs.dedecms.com/269491.html
- 快速乘法,幂计算 hdu5666
在实际应用中为了防止数据爆出,在计算a*b%m和x^n%m时,可以采用此方法.在数论中有以下结论: a*b%m=((a%m)*(b*m))%m ; (a+b)%m=(a%m+b%m)%m ; _int ...
- 鸟哥的linux私房菜服务器架设篇之准备工作和网络基础
架设服务器的基本功课 1基础网络的基本概念,以方便进行联网和设定及除错 2熟悉操作系统的简易操作:包括登录分析,账号管理,文本编辑器的使用等等的技巧 3信息安全方面:包括防火墙与软件更新方面的相关知识 ...
- 修改Linux基本配置
1.修改主机名 vi /etc/sysconfig/network NETWORKING=yes HOSTNAME=server1.cn 2.修改ip地址 vi /etc/sysconfig/netw ...
- Android开发之布局文件里实现OnClick事件关联处理方法
一般监听OnClickListener事件,我们都是通过Button button = (Button)findViewById(....); button.setOClickLisener....这 ...
- jquery插件jTemplates使用方法
简单记一下我所做项目中用到的代码,以备以后用的时候一看明确了. 1.jsp(jquery-jtemplates.js下载地址:http://download.csdn.net/detail/xlb74 ...
- 让heigh:100%起作用
如何让 height:100%; 起作用 http://www.webhek.com/css-100-percent-height 当你设置一个页面元素的高度(height)为100%时,期望 ...