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)
})
}
 
// 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'的更多相关文章

  1. 转 查看磁盘IO负载 - 看哪些进程在读写磁盘 以及oracle 异步I/O 和同步I/O

    https://www.cnblogs.com/cloudstorage/archive/2012/11/11/2764623.html #####sample 1: Oracle等待事件db fil ...

  2. spring Batch实现数据库大数据量读写

    spring Batch实现数据库大数据量读写 博客分类: spring springBatchquartz定时调度批处理  1. data-source-context.xml <?xml v ...

  3. MySQL/MariaDB数据库的PROXY实现读写分离

    MySQL/MariaDB数据库的PROXY实现读写分离 作者:尹正杰  版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.ProxySQL概述 1>.各家互联网公司读写分离的解决方案 m ...

  4. [转]Visual Studio 2008中如何比较二个数据库的架构【Schema】和数据【Data】并同步

    使用场景: 在团队开发中,每一个人都有可能随时更新数据库,这时候数据库中数据和架构等信息都会发生变化.如果更新不及时,就会发生数据错误或数据丢失的风险,影响团队的开发效率和 项目进度,这时候我们该怎么 ...

  5. 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 ...

  6. Capistrano:自动完成多台服务器上新版本的同步更新,包括数据库的改变

    https://baike.baidu.com/item/Capistrano/6844928?fr=aladdin   Capistrano是一种在多台服务器上运行脚本的开源工具,它主要用于部署we ...

  7. 如果数据库上的row格式是mixed或者mixed的格式,如何对比两台数据库服务器上的数据是否一致呢

    如果数据库上的row格式是mixed或者mixed的格式,如何对比两台数据库服务器上的数据是否一致呢

  8. SQL Server数据库 备份A库,然后删除A库,再还原A库,此时数据库一直显示“正在还原”的解决方法

    SQL Server数据库 备份A库,然后删除A库,再还原A库,此时数据库一直显示"正在还原"的解决方法: A库一直显示"正在还原". 在这种状态下,由于未提交 ...

  9. 一个适合变化的产品部署集成包(nginx+jdk+tomcat+nodejs+mysql+redis+mongo+MYSQL主主(读写分离)集群建立+代码包+持续上线+备份)

    一.前言 最近公司做了一套新产品,需要发布到不确定的硬件环境中(不同使用单位规模,使用人数,服务器提供的资源不同)若每次进行人工部署耗时费力,周期过长. 二.分析 具体的部署流程如下: 由上图流程进行 ...

随机推荐

  1. OpenSSL使用1(用OpenSSL生成自签名证书在IIS上搭建Https站点)(用于iOS的https访问)

    前提: 先安装openssl,安装有两种方式,第一种直接下载安装包,装上就可运行:第二种可以自己下载源码,自己编译.这里推荐第一种. 安装包:http://slproweb.com/products/ ...

  2. 聊聊、Zookeeper Linux 启动

    Zookeeper 在 windows 下安装比较简单,属于无脑式安装,下载下来双击脚本就可以了.前面的文章中也有介绍,今天我来写写 Linux 下的安装,以及所碰到的坑. 首先,登陆 Linux 系 ...

  3. 2013年9月29日 iOS 周报

    新闻 Apple Tech Talks 2013 在中国上海的iOS Tech Talks活动将于11月12日展开,活动主要针对iOS 7.活动分为App开放日和游戏开放日,主要内容可查看链接.当你看 ...

  4. [深入浅出iOS库]之数据库 sqlite

    一,sqlite 简介 前面写了一篇博文讲如何在 C# 中使用 ADO 访问各种数据库,在移动开发和嵌入式领域也有一个轻量级的开源关系型数据库-sqlite.它的特点是零配置(无需服务器),单磁盘文件 ...

  5. Android 控件架构与自定义控件详解

    架构: PhoneWindow 将一个 DecorView 设置为整个应用窗口的根 View,这里面所有 View 的监听事件,都通过 WindowManagerService 来接收.DecorVi ...

  6. Android Touch事件传递机制详解 上

    最近总是遇到关于Android Touch事件的问题,如:滑动冲突的问题,以前也花时间学习过Android Touch事件的传递机制,可以每次用起来的时候总是忘记了,索性自己总结一下写篇文章避免以后忘 ...

  7. 简单便捷的纯PHP网盘程序 Veno File Manager 2.6.3(VFM2)

    体验过很多国外网盘程序,例如:Owncloud.Bedrive.YetiShare.XFilesharing.uCloud.Cloudshare 等等,诸如此类,VFM2与这些臃肿的商用或非商用来的程 ...

  8. 左手系,右手系,row major, column major

    http://www.cnblogs.com/minggoddess/p/3672863.html dx 左手系 row major ogl 右手系 column major 差了个 matrix   ...

  9. ElasticSearch搜索term和terms的区别

    今天同事使用ES查询印地语的文章.发现查询报错,查询语句和错误信息如下: 查询语句:{    "query":{        "bool":{         ...

  10. JAVA Eclipse开发Android程序会经常闪退是怎么回事

    类没有new就直接用会闪退,比如下面我在前面声明了ClientSocket的类,点击连接按钮之后,如果不先new就直接Connect就会闪退   你在当前页面创建findViewById的时候,如果找 ...