Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. user = {
  2. "userId" : "myId",
  3. "connections":
  4. [{
  5. "dateConnectedUnix": 1334567891,
  6. "isActive": true
  7. }, {
  8. "dateConnectedUnix": 1334567893,
  9. "isActive": false
  10. }]
  11. }
  12.  
  13. user = {
  14. "userId" : "myId",
  15. "connections":
  16. [{
  17. "dateConnectedUnix": 1334567893,
  18. "isActive": false
  19. }]
  20. }
  21.  
  22. userAccounts.update({'connections.isActive': false },
  23. {$pull: { 'connections.isActive':false }},
  24. function (err,val) {
  25. console.log(val)
  26. });
  27.  
  28. userAccounts.update({'connections._id': '1234-someId-6789' },
  29. {$pull: { 'connections._id': '1234-someId-6789' }},
  30. function (err,val) {
  31. console.log(val)
  32. });
  33.  
  34. userAccounts.update(
  35. { userId: usr.userId },
  36. { $pull: { connections : { _id : connId } } },
  37. { safe: true },
  38. function removeConnectionsCB(err, obj) {
  39. ...
  40. });
  41.  
  42. var ObjectId = require('mongoose').Types.ObjectId;
  43.  
  44. userAccounts.update({'connections._id': new ObjectId('1234-someId-6789') },
  45. {$pull: { 'connections._id': new ObjectId('1234-someId-6789') }},
  46. function (err,val) {
  47. console.log(val)
  48. });
  49.  
  50. Customer.findOneAndUpdate(query, {$pull: {address: addressId}}, function(err, data){
  51. if(err) {
  52. return res.status(500).json({'error' : 'error in deleting address'});
  53. }
  54.  
  55. res.json(data);
  56.  
  57. });
  58.  
  59. const removeTansactionFromUser = (userId, connectionId) => {
  60. return User.findByIdAndUpdate(userId, { $pull: { "connections": connectionId} }, {'new': true} );
  61. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement