我正在尝试批量处理数据库更新以重新填充mongo集合。我创建了一个对象来保存从外部源查找数据所需的属性,然后将其添加回MongoDb集合。
数组如下所示:
const pops = [
{ table: 'SFAccounts',
label: 'Account__c',
createListName: 'Accounts'
},
{ table: 'SFTimes',
label: 'CusTime__c',
createListName: 'Time'
}]
我想创建一个带有'table','label和'createListName'的函数,它基本上就像这样......
async function processData(table, label, createListName) {
// Get some info from Salesforce
const dataFromSF = await getMetaDataFromSalesForce(table)
// Extract the parts I actually need
const relevantBits = dataFromSF.filter(field => field.name === label)
//Create a new list in the db
const createResult = await List.create( { name: createListName, values: relevantBits } )
return createResult
}
最终目标是达到类似
的目标await Promise.all(processData(pops))
将等待所有被拉入并填充到数据库中的表。
答案 0 :(得分:1)
如果更改processData的参数:
async function processData({table, label, createListName}) {
// Get some info from Salesforce
const dataFromSF = await getMetaDataFromSalesForce(table)
// Extract the parts I actually need
const relevantBits = dataFromSF.filter(field => field.name === label)
//Create a new list in the db
const createResult = await List.create( { name: createListName, values: relevantBits } )
return createResult
}
只是await Promise.all(pops.map(processData));