This is my code for update many records with mongodb.
const nfts = await waxModel.find();
console.log(nfts.length) // -> 121
// Option 1: using map()
nfts.map(async nft => {
nft.trait_attribute = null;
await nft.save();
});
// Option 2: using loop
for (let i = 0; i < nfts.length; i++) {
nfts[i].trait_attribute = null;
await nfts[i].save();
}
- This is my DB, no recored have trait_attribute: null:
- This is the first result when I use map(), only have 2 records:
- And this is the second result when I use for loop:
I don't know that is the problem. In my previous question: I know map methods don't handle the asynchronous function but it's still have full records not missing many updated records as now. Thank for your attention.


