storoge

Untitled

Feb 22nd, 2017
90
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.addresses.find({ $or: [
  16. { "area": /.*Химк.*/i },
  17. { "area": /.*химк.*/i },
  18. { "area": /.*ХИМК.*/i }
  19. ]}).addOption(DBQuery.Option.noTimeout).forEach(function(adr){
  20.  
  21. if(adr != undefined ){
  22.  
  23. if(adr.personId != undefined )
  24. {var personId = oid(adr.personId);}
  25. else {var personId = oid(0);}
  26.  
  27. //printjson(registrationAddressId);
  28. //printjson(locationAddressId);
  29.  
  30. var person = db.persons.findOne({"_id": personId});
  31.  
  32. //var person2 = stage.xx_deadline_aggr.findOne({"_id": personId});
  33.  
  34. if(person != undefined && person.length > 0)
  35. {
  36. stage.xx_deadline_aggr.save(person);
  37. counter = counter + 1;
  38. }
  39.  
  40. }
  41. });
  42. print("Total " + counter + " persons.");
RAW Paste Data