我有一个批量操作,我每 2 小时在我的 mongodb 数据库中插入 10000 个项目。代码看起来像这样
let bulk = models.Product.collection.initializeUnorderedBulkOp();
...
if (bulk.length > 0) {
bulk.find({
"$or": [
{
"updatedAt": {
"$lt": timestamp
}
},
{
"discount": {
"$eq": 0
}
}
]
}).remove()
bulk.execute((error, result) => {
if (error) {
console.error('Error while inserting products' + JSON.stringify(error))
}
else {
console.log('Successfully inserted ' + result.nInserted + ' upserted ' + result.nUpserted + ' matched ' + result.nMatched + ' modified ' + result.nModified + ' removed ' + result.nRemoved)
}
})
}
else {
console.log('There were no bulk operations to execute ' + products.length)
}
}
我的连接不断超时。我的猫鼬连接选项如下所示
let options = {
mongos: {
ssl: true,
sslValidate: true,
sslCA: ca,
}
}
我很清楚其他 stackoverflow 线程上正在讨论的这个连接设置
server: {
socketOptions: {
keepAlive: 300000,
connectTimeoutMS: 30000
}
}
我阅读了 keepAlive 和 connectTimeoutMS 的文档,但我怎么知道两者的正确值,我是否也需要 socketTimeoutMS?
提前感谢您的建议
更新 1
我不断收到此错误:
{"name":"MongoError","message":"connection 0 to aws-ap-southeast-1-portal.2.dblayer.com:15284 timed out"}
我的连接选项现在看起来像这样 //compose.io 数据库的选项
let options = {
mongos: {
ssl: true,
sslValidate: true,
sslCA: ca,
},
server: {
socketOptions: {
keepAlive: 300000,
connectTimeoutMS: 300000
}
},
replset: {
socketOptions:
{
keepAlive: 300000,
connectTimeoutMS: 300000
}
}
}