Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用DynamoDB的批量Upsert_Node.js_Mongodb_Amazon Dynamodb_Nestjs - Fatal编程技术网

Node.js 使用DynamoDB的批量Upsert

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

在DynamoDB中是否可以像mongodbbulkwrite那样进行项的大容量上传

我在MongoDB中有这个函数,希望在DynamoDB中做类似的事情:

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++;
}
返回;
}
您有两个选择:

  • 使用。在这种情况下,DynamoDB将基本上为您处理并发性,并行运行多个单独的写请求。在处理任何失败的请求时都会有一些开销
  • 使用请求,并使用节点工作线程模块在客户端实现并发