json - Aggregate Method Not Getting Updated Data MongoDB -
So when I do a DELETE request, so I'm updating our model and have been removed from the selected Array items . Then I am sending updated JSON data via AJAX. I am using the overall method to determine the amount of values selected in an array, but the problem is that the overall method is returning data based on the data available, although I put it in the callback. So how do I get the correct update amount? Here's the code I'm doing what I use:
regUser.findOneAndUpdate ({username: req.user.username}, {$ bridge: {Budget: {uniqueId: parseFloat (req.param ( 'id'))}}}, function (err, data) {if (err) return console.log (err); regUser.aggregate ([{$ match: {username: req.user.username}}, / / unwind the { "$ group": { "$ group": { "_id": "$ _id", "expense": { "Total group with conditions including $ sum {" $ unwind ":" $ budgets " }, ": {" $ cond ": [" $ budgets.expense "," $ budgets.value ", 0]}}," non-Akspens ": {" $ sum ": {" $ cond ": [" $ budgets.expense ", 0," $ budgets.value "]}}}}}, function (err, Agreedeta) {sumData = aggData}); res.json ({sumData: sumData, budgetList: data.budgets}) ;});
async programming found :) Move:
< code> res.json ({sumData: sumData, budgetList: data.budgets}); Inside the regUser.gregate callback function.
function (err, aggData) {res.json ({sumData: aggData, budgetList: data.budgets}); });
Comments
Post a Comment