Guest User

Untitled

a guest
Mar 22nd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. {
  2. "_id": "5aa9535c6c4f437de713452a",
  3. ...
  4. "ht_score": "[0-1]",
  5. "ft_score": "[1-3]",
  6. "et_score": null,
  7. "penalty_local": null,
  8. "penalty_visitor": null,
  9. "comp_name": "UEFA Champions League",
  10. "predictions": [
  11. {
  12. "name": "Ilker Baltaci",
  13. "userid": "*******",
  14. "userFbid": "*****",
  15. "local_team_score": "3",
  16. "away_team_score": "1",
  17. "status": "FT"
  18. },
  19. {
  20. "name": "M. Mustermann",
  21. "userid": "*******",
  22. "userFbid": "*****",
  23. "status": "FT"
  24. }
  25. ],
  26. "match_id": "2324756"
  27. }
  28.  
  29. var bulk = db.collection('bets').initializeUnorderedBulkOp();
  30.  
  31. return new Promise(function (resolve, reject) {
  32. try {
  33. predictions.forEach(function (currentPrediction) {
  34. //Find one and update
  35. let match = games[currentPrediction.match_id];
  36. const query = {'_id': new ObjectID(currentPrediction._id)};
  37. bulk.find(query).update(
  38. {
  39. $set: {
  40. status: match.status,
  41. timer: match.timer,
  42. localteam_score: match.localteam_score,
  43. visitorteam_score: match.visitorteam_score,
  44. ht_score: match.ht_score,
  45. ft_score: match.ft_score,
  46. et_score: match.et_score,
  47. penalty_local: match.penalty_local,
  48. penalty_visitor: match.penalty_visitor,
  49. "predictions.$[].status" : "FT"
  50. }
  51. },{ multi: true });
  52. })
  53.  
  54. bulk.execute(function (err) {
  55. resolve(predictions)
  56. });
  57. }
  58. catch
  59. (e) {
  60. reject(e);
  61. }
  62. }
Add Comment
Please, Sign In to add comment