Advertisement
storoge

Untitled

Feb 22nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. function oid(id) {
  2. try {
  3. return ObjectId(id);
  4. } catch(e) {
  5. return id;
  6. }
  7. }
  8.  
  9. var counter = 0;
  10.  
  11. var stageConn = new Mongo("10.10.80.227:27017");
  12. var stage = stageConn.getDB("rldd2");
  13. var remove = stage.xx_deadline_aggr.remove({});
  14.  
  15. db.persons.find({ "type": { $ne: "JURIDICAL" }}).addOption(DBQuery.Option.noTimeout).forEach(function(person){
  16. if(person != undefined ){
  17.  
  18. if(person.registrationAddressId != undefined )
  19. {var registrationAddressId = oid(person.registrationAddressId);}
  20. else {var registrationAddressId = oid(0);}
  21.  
  22. if(person.locationAddressId != undefined )
  23. {var locationAddressId = oid(person.locationAddressId);}
  24. else {var locationAddressId = oid(0);}
  25.  
  26. //printjson(registrationAddressId);
  27. //printjson(locationAddressId);
  28.  
  29. var regAddr = db.addresses.findOne({"_id": registrationAddressId});
  30. var locAddr = db.addresses.findOne({"_id": locationAddressId});
  31. // printjson(regAddr);
  32. //printjson(locationAddressId);
  33.  
  34. if(regAddr != undefined )
  35. {var regArea = regAddr.area;}
  36. else {var regArea = "1";}
  37.  
  38. if(locAddr != undefined )
  39. {var locArea = locAddr.area;}
  40. else {var locArea = "1";}
  41.  
  42. if(regArea == undefined ){var regArea = "1";}
  43. if(locArea == undefined ){var locArea = "1";}
  44.  
  45. //printjson(regArea);
  46. //printjson(locArea);
  47.  
  48. //printjson(regArea);
  49. //printjson(locArea);
  50.  
  51.  
  52. if( regArea.indexOf("химк") >=0 || regArea.indexOf("Химк") >=0 ||regArea.indexOf("ХИМК") >=0 || locArea.indexOf("химк") >=0 || locArea.indexOf("Химк") >=0 ||locArea.indexOf("ХИМК") >=0)
  53. {
  54. stage.xx_deadline_aggr.save(person);
  55. counter = counter + 1;
  56. }
  57. }
  58. });
  59. print("Total " + counter + " persons.");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement