Arrays 基于另一个数据集筛选大型JSON数据集

Arrays 基于另一个数据集筛选大型JSON数据集,arrays,node.js,json,filter,Arrays,Node.js,Json,Filter,我有一个大型JSON数据集a(180000条记录),其中包含用户的完整记录,另一个JSON数据集B(是a的子集)仅包含一些用户的唯一ID和名称(约1500条记录)。我需要从数据集A获取数据集B中用户的完整记录 这是我到目前为止试过的 let detailedSponsoreApplicants = []; let j; for(j=0; j < allApplicants.length; j++){ let a = allApplicants[j];

我有一个大型JSON数据集a(180000条记录),其中包含用户的完整记录,另一个JSON数据集B(是a的子集)仅包含一些用户的唯一ID和名称(约1500条记录)。我需要从数据集A获取数据集B中用户的完整记录

这是我到目前为止试过的

let detailedSponsoreApplicants = [];
let j;
        for(j=0; j < allApplicants.length; j++){
            let a = allApplicants[j];

            let i;
            for(i=0; i < sponsoredApplicants.length;; i++){
                let s = sponsoredApplicants[i];
                if (s && s.number === a.applicationNumber) {
                    detailedSponsoreApplicants.push(a);
                }else{                
                    if(s){
                        logger.warn(`${s.number} not found in master list`);
                    }
                }
            }

        }
尝试与以下人员合作:

node --max-old-space-size=1024 index.js #increase to 1gb
node --max-old-space-size=2048 index.js #increase to 2gb
node --max-old-space-size=3072 index.js #increase to 3gb
node --max-old-space-size=4096 index.js #increase to 4gb
node --max-old-space-size=5120 index.js #increase to 5gb
node --max-old-space-size=6144 index.js #increase to 6gb
node --max-old-space-size=7168 index.js #increase to 7gb
node --max-old-space-size=8192 index.js #increase to 8gb
此外,您的脚本可能需要很长时间才能运行。如果想提高性能,可以考虑使用或将大型数组转换为快速查找对象:

const obj = a.reduce((obj, current) => {
  obj[current.applicationNumber] = current;
  return obj;
}, {});
然后,您可以在固定时间内查找全部详细信息:

const fullDetailsOfFirstObject = obj[B[0].number];
尝试与以下人员合作:

node --max-old-space-size=1024 index.js #increase to 1gb
node --max-old-space-size=2048 index.js #increase to 2gb
node --max-old-space-size=3072 index.js #increase to 3gb
node --max-old-space-size=4096 index.js #increase to 4gb
node --max-old-space-size=5120 index.js #increase to 5gb
node --max-old-space-size=6144 index.js #increase to 6gb
node --max-old-space-size=7168 index.js #increase to 7gb
node --max-old-space-size=8192 index.js #increase to 8gb
此外,您的脚本可能需要很长时间才能运行。如果想提高性能,可以考虑使用或将大型数组转换为快速查找对象:

const obj = a.reduce((obj, current) => {
  obj[current.applicationNumber] = current;
  return obj;
}, {});
然后,您可以在固定时间内查找全部详细信息:

const fullDetailsOfFirstObject = obj[B[0].number];

也许不是最有效的方法,但有效的方法是:

1) 将数据集A(大数据集)导入数据库。例如,或您熟悉的数据库

2) 为字段
applicationNumber
添加索引

3) 为数据集B中的每个元素查询数据库,或尝试批量查询(一次选择多个)


我以前在一个类似的用例中做过这项工作,但在您的案例中,可能有更好的方法来完成这项工作。

也许不是最有效的方法,但有效的方法是:

1) 将数据集A(大数据集)导入数据库。例如,或您熟悉的数据库

2) 为字段
applicationNumber
添加索引

3) 为数据集B中的每个元素查询数据库,或尝试批量查询(一次选择多个)


我以前在一个类似的用例中也这样做过,但在你的例子中,可能还有更好的方法。

你能分享你的JSON示例吗。将整个对象读入内存是不可行的,所以你可以尝试@Eldar Thank,我会尝试一下。你可以分享你的JSON的一个样本吗?把整个对象读入内存是不可行的,所以你可以试试“ELDAR”之类的东西,谢谢,我会试试看。如果其他选项都失败了,我会考虑的。如果你坚持下去,我会尽力帮助你。谢谢,如果所有其他选项都失败了,我会考虑的。如果你坚持下去,只要打电话给我,我会尽力帮忙的。