I know this question has been answered here, however every single answer doesn't work in my script, asking this was my very last resort.
I am trying to find new data uploaded to a database, this is the logic it follows:
Read data from my Mongo database store as a
>> Pull new data from sql server, store as b
>> filter the data and overwrite my Mongo database >> compare a
and b
to find new documents uploaded.
Here is the code I have so far:
function comparer(otherArray){
return function(current){
return otherArray.filter(function(other){
return other.value == current.value && other.display == current.display
}).length == 0;
}
}
var onlyInA = a.filter(comparer(b));
var onlyInB = b.filter(comparer(a));
result = onlyInA.concat(onlyInB);
console.log(result);
I obtain a
and b
like so:
a = await dbo.collection("master").find({ }, {projection:{_id: 0}}).toArray();
//upload all new data here, so b contains more objects than a
b = await dbo.collection("master").find({ }, {projection:{_id: 0}}).toArray();
I am expecting this to return all objects in b
except if the objects exist in a
, so I should see new data.
Here is a brief sample of my database;
a = [{
"Process": "Process1",
"Num": "000000",
}]
b = [{
"Process": "Process1",
"Num": "000000",
},
{
"Process": "Process2",
"Num": "000107",
}]
Therefore b
contains more objects, so finding the difference should show the object containing process 2. Thanks for any help!