Node.js 使用DynamoDB的批量Upsert
在DynamoDB中是否可以像mongodbbulkwrite那样进行项的大容量上传 我在MongoDB中有这个函数,希望在DynamoDB中做类似的事情:Node.js 使用DynamoDB的批量Upsert,node.js,mongodb,amazon-dynamodb,nestjs,Node.js,Mongodb,Amazon Dynamodb,Nestjs,在DynamoDB中是否可以像mongodbbulkwrite那样进行项的大容量上传 我在MongoDB中有这个函数,希望在DynamoDB中做类似的事情: async bulkSync( model: any | null, context: any[], filterKeys: Array<string> = ['_id'], ): Promise<any> { let operations = []; // Initialize th
async bulkSync(
model: any | null,
context: any[],
filterKeys: Array<string> = ['_id'],
): Promise<any> {
let operations = []; // Initialize the bulk operations array
let i = 1;
for (const record of context) {
const filter: any = {};
for (const key of filterKeys) {
const path = key.split('.');
const value = R.path(path, record);
filter[key] = value;
}
operations.push({
updateOne: {
filter: filter,
update: {
$set: record,
$setOnInsert: {
created_at: record.updated_at,
},
},
upsert: true, // example update operation,
setDefaultsOnInsert: true,
},
});
if (operations.length % 500 === 0 || i === context.length) {
await model.collection.bulkWrite(operations, {
ordered: true,
w: 1,
});
operations = [];
}
i++;
}
return;
}
async bulkSync(
型号:任意|空,
上下文:任何[],
filterKeys:Array=[''u id'],
):承诺{
let operations=[];//初始化批量操作数组
设i=1;
for(上下文的常量记录){
常量过滤器:any={};
for(筛选键的常量键){
const path=key.split('.');
常量值=R.path(路径,记录);
过滤器[键]=值;
}
操作.推送({
更新日期:{
过滤器:过滤器,
更新:{
$set:创纪录,
$setOnInsert:{
创建时间:record.updated时间:,
},
},
upsert:true,//更新操作示例,
setDefaultsOnInsert:true,
},
});
if(operations.length%500==0 | | i==context.length){
等待模型。收集。批量写入(操作{
命令:是的,
w:1,
});
操作=[];
}
i++;
}
返回;
}
您有两个选择: