mongoDB bulk insert data
var requests = [];
cursor.forEach(document => {
var emailArray4DO = [];
var emailArray4EP = [];
var ioJsonArray = document.IndividualsOwnersPara;
for (var i1 in ioJsonArray) {
var array = ioJsonArray[i1].split("|");
if (emailArray4DO.length < 5) {
emailArray4DO.push(array[array.length - 1]);
}
}
var epJsonArray = document.EngagementPartnerPara;
for (var i2 in epJsonArray) {
var array = epJsonArray[i2].split("|");
if (emailArray4EP.length < 1) {
emailArray4EP.push(array[array.length - 1]);
}
}
requests.push({
updateOne: {
filter: { _id: document._id },
update: { $set: { Email4DO: emailArray4DO, Email4EP: emailArray4EP } }
}
});
if (requests.length === 500) {
db.CitationSource1.bulkWrite(requests);
requests = [];
}
});
if (requests.length > 0) {
db.CitationSource1.bulkWrite(requests);
}