트랜잭션을 업서 링하는 데 몽구스의 대량 작업을 사용하고 싶습니다. 각 트랜잭션에 대해 루프에서 루프를 처리하고 루프 내에서 약속을 사용해야합니다. 그 약속이 끝난 후, 나는 업서 트를 대량으로 추가하고 싶다.JavaScript - async/해결할 때까지 기다리지 않고 기다려야합니다.
내 모든 문제가 끝날 때까지 내가 await
이긴하지만 약속이 해결되기 전에 함수의 끝에서 대량이 실행됩니다. 내가 잘못했거나 어떻게 해결할 수 있습니까?
const bulkTransactions = Transaction.collection.initializeUnorderedBulkOp();
transactions.forEach(async (transaction: any) => {
// do some suff, fill transaction_data
await Utils.processTransactionType(transaction).then((action: any) => {
if (action) {
// do other stuff
}
bulkTransactions.find({_id: hash}).upsert().replaceOne(transaction_data);
}).catch((err: Error) => {
// log error
});
});
await bulkTransactions.execute().catch((err: Error) => {
// log error
});
'transactions.forEach' 무엇입니까? 콜백에 의해 반환 된 약속을 어떻게 처리합니까? – Bergi
트랜잭션은 트랜잭션 객체의 배열입니다. 나는''forEach'''로 배열을 가로 지른다. – phoebus
글쎄 그게 문제이다 :-) – Bergi