Hello,
Can this be done using insertMany in batches? I am using the below script.
I thought exporting any collection documents to another collection can be done easily. Could you please advice if I may overlooking something here.
var docsToInsert = db.PMForms_local.find({ “exist”: “yes” }).toArray();
var batchSize = 20;
var successfulInserts = 0;
for (var i = 0; i < docsToInsert.length; i += batchSize) {
var batch = docsToInsert.slice(i, i + batchSize);
try {
var result = db.collectionB.insertMany(batch);
successfulInserts += result.insertedCount;
} catch (e) {
print("Error inserting batch starting at index " + i + ": " + e.message);
}
}