I am using find to query and then insert almost 1000 documents in a mongodb collection.Is there a way to limit the number of documents being inserted at the same time.(My basic objective here is to find all documents with a particular year from a collection and then copy/insert them within the same collection with updated year and few other sections.The problem is when this API is in progress other API's gets a delay.So I need to change the concurrency rate at which these happens).
async function Options(fromYear,toYear){
await db.collection('Options').find({"year":parseInt(fromYear)}).forEach(function(doc){
var newDoc = doc;
delete newDoc._id;
newDoc.year = parseInt(toYear);
db.collection('Options').insert(newDoc);
});
}