我有一个批量操作,在我的mongodb数据库中每两个小时upsert 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)
}
}
我的连接一直超时。 我的mongoose连接选项如下所示
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
}
}
}