In my efforts to ensure that my table data remains synchronized with the database information, I have encountered an issue.
Whenever Data Changes:
$scope.changeStatus = function($event,label,status){
var target = $event.currentTarget;
target = $(target).parents('tr').attr('id');
$http({
method: 'POST',
url: '/update',
params: {
trgt : target,
label : label,
labelstatus : status,
searchQuery : $scope.search
}
})
.success(function(data){
console.log(data);
$scope.events = data;
})
.error(
function(error){
console.log(error)
});
}
Next:
app.post('/update', function(req,res){
ImportCollection.findOne({ _id : req.query.trgt },function(err,doc){
doc.label.label = req.query.labelname;
doc.label.status = req.query.labelstatus;
doc.save();
});
// UNTIL HERE EVERYTHING WORKS JUST FINE
if(req.query.searchQuery){
ImportCollection.find({$or:[
{'localizedData.0.title' : {'$regex': req.query.searchQuery, $options: 'i' }},
{'licensor.name' : {'$regex': req.query.searchQuery, $options: 'i'}}
]})
.exec(function(err, imports){
if(err) throw err
res.json(imports)
})
} else{
ImportCollection.find({},function(err, imports){
if(err) throw err
res.json(imports)
})
}
});
However, there is a delay in updating the table data after each request. For example, when changing from "Live" to "QA", the table still shows "Live". Only after changing it to "DENIED", does the table reflect the change to "QA". This inconsistency persists in the data updates.
Any suggestions or insights on how to resolve this issue?