I have a json file that I want to check if the document already exist in the database and then add a ‘YES’ or ‘NO’ on the on the ‘DUPLICATE’ key of the json file. Below is the my code snippet.
jsonFile.forEach(val => {
let dup = MyCollection.find({ $or: [ { EMAIL: val.EMAIL }, { PHONE: val.PHONE }, { FULLADDRESS: val.FULLADDRESS} ] }).fetch();
if (dup.length > 0) {
val.DUPLICATE = ‘YES’;
} else {
val.DUPLICATE = ‘NO’;
}
});
So the code is simple and work but my issue is that I my json file sometimes has more than 55,000 documents and it takes a long time to do the check. I tried to use aggregate but came up with almost the same results.
myCollection.aggregate(
[{$match : { $or: [ { EMAIL: EMAIL }, { PHONE: val.PHONE }, { FULLADDRESS: FULLADDRESS} ] }}]);
Is there a better way to do this? or any recommendations?