2
I have 2 object arrays, one of them is composed of emails that comes from the provider through IMAP protocol and I convert to objects and then put in an array all of it.
The other is an array of emails that I search in Mongodb and have the same structure as the first email, follow example:
{
"_id" : ObjectId("59af03cb4a202223c4cf7bea"),
"idEmail" : "DM5PR13MB10209695536A9A5B3119967CCD960@DM5PR13MB1020.namprd13.prod.outlook.com",
"remetente" : "[email protected]",
"destinatario" : "[email protected]",
"assunto" : "Teste de gravação no banco",
"texto" : "Email diferente para gravar no banco\n",
"box" : "INBOX"
}
What I want to do is a function that compares the two arrays, does not delete anything from DB, just save the differences (in case the latest emails coming from the provider).
However the two arrays do not have the same size, the array that comes with the new emails will always be bigger than the one that is already in DB.
What I need (and am trying) to do is: Compare the two arrays and add in Mongodb only the differences.
Only I’ve done a lot of research and so far I haven’t found anything to solve my problem...
I’ll try it out right here
– LeonardoEbert
I couldn’t understand where I could put this function in my code: https://codepen.io/LeonardoEbert/pen/mMYVjO?editors=1011
– LeonardoEbert
I implemented the code, but it saves the whole array, concatenates the 2 arrays and saves everything in the database, here is the complete code: https://jsfiddle.net/dxkyh3d8/1/
– LeonardoEbert
I don’t understand what the problem is now! :)
– CarvBru
I’m still learning, and I kind of got a solution to compare the arrays: https://jsfiddle.net/pzmb75oy/ Since the 2 arrays are the same sequence, but the one coming from the provider has new objects at the end, then I got the ID’s of the respective positions of each array and now I need to capture those that are the new emails, thank you if you can take a look at that jsfiddle link...
– LeonardoEbert