Node.js 正在尝试将多个项目上载到cosmos db
我试图逐行读取文件,一旦达到500行,我将创建一个cosmos db容器客户端并上传数据。这样,我就为每500条线路共享一个连接。 这是我的密码:Node.js 正在尝试将多个项目上载到cosmos db,node.js,azure-cosmosdb,azure-cosmosdb-sqlapi,Node.js,Azure Cosmosdb,Azure Cosmosdb Sqlapi,我试图逐行读取文件,一旦达到500行,我将创建一个cosmos db容器客户端并上传数据。这样,我就为每500条线路共享一个连接。 这是我的密码: lineReader.eachLine(pathToFile, (line, last) => { lineCount += 1 let insertItem = JSON.parse(line) linesList.push(insertItem)
lineReader.eachLine(pathToFile, (line, last) => {
lineCount += 1
let insertItem = JSON.parse(line)
linesList.push(insertItem)
if (lineCount % 500 === 0) {
//create copy of lineslist and empty the actual list
let tempList = [...linesList]
linesList = []
getContainer('dummy2', 'type').then(container => {
tempList.map((lineToBeInserted, pos) => {
container.items.create(lineToBeInserted).then(dbItem => {
if (last) {
res.end('\r\n written all data to db')
} else {
res.write('writtem to db')
}
})
以下是我在配置中的getContainer方法:
async function getContainer(name, partitionKey) {
partitionKey = "/" + partitionKey
let pk = getConfig(name, partitionKey).partitionKey
return _client
.database(_databaseId)
.containers.createIfNotExists({
id: name,
pk
}, {
offerThroughput: 5000
}).then(container => {
return _db.container(container.container.id)
}).catch(err => {
console.log(err)
})
}
但是我在创建项的.create()方法中遇到了ETIMEDOUT错误:
FetchError: request to https://brand-consumer-analytics-eastasia.documents.azure.com:443/dbs/quilt/colls/dummy2/docs failed, reason: connect ETIMEDOUT 23.102.239.134:443
at ClientRequest.<anonymous> (D:\Polynomial Projects\Compare Blob with db\node_modules\node-fetch\lib\index.js:1461:11)
at ClientRequest.emit (events.js:315:20)
at TLSSocket.socketErrorListener (_http_client.js:426:9)
at TLSSocket.emit (events.js:315:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
type: 'system',
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
headers: {
'x-ms-throttle-retry-count': 0,
'x-ms-throttle-retry-wait-time-ms': 0
}
}
FetchError:请求https://brand-consumer-analytics-eastasia.documents.azure.com:443/dbs/quilt/colls/dummy2/docs 失败,原因:连接ETIMEDOUT 23.102.239.134:443
在ClientRequest。(D:\polymonal Projects\Compare Blob与db\node\u modules\node fetch\lib\index.js:1461:11)
在ClientRequest.emit(events.js:315:20)
在TLSSocket.socketErrorListener(_http_client.js:426:9)
在TLSSocket.emit(events.js:315:20)
在发射时出错(内部/streams/destroy.js:92:8)
在emitErrorAndCloseNT(内部/streams/destroy.js:60:3)
在处理和拒绝时(内部/process/task_queues.js:84:21){
键入:“系统”,
errno:“ETIMEDOUT”,
代码:“ETIMEDOUT”,
标题:{
“x-ms-throttle-retry-count”:0,
“x-ms-throttle-retry-wait-time-ms”:0
}
}
无法获取此错误的原因。当我跳过行检查并为每条记录创建一个容器客户端时,错误将不会显示。是否尝试将行数减少为400、300、200。。?我怀疑拥有500件物品对网络来说可能是压倒性的。看看stacktrace,它看起来像是节点网络堆栈中的错误,而不是来自CosmosDB端。我很困惑。您是否为每500个项目创建一个新容器,然后将数据插入新容器中?您好@krishg,是的,我尝试过减少计数,但没有成功。有没有办法增加cosmos db的超时时间?示例
lineToBeInserted
是什么样子的?json文档?是的,lineToBeInserted是json文档。