본문 바로가기
데이터베이스

mongo mongo_slave_server_host:port database < file.js > dump_users_`date +%Y%m%d`.log

by 혜룐 2018. 7. 3.


mongo file.js

$ cat users_find_by_created_at.js

use users;

rs.slaveOk();

db.users.find( {"created_at":{$gte: ISODate("2010-01-01T00:00:00Z"), $lte:ISODate("2010-06-01T00:00:00Z")}} ).sort({"created_at":-1}).forEach(function(entry){

print("_id = "+entry._id+", gender = "+entry.gender+", birth = "+entry.birthday+", name = "+entry.username + ", phone = "+entry.phone);

//print("USER = "+ JSON.stringify(entry));

}); 


위 스크립트 실행

$ mongo mongo_slave_server_host:port database < file.js > dump_users_`date +%Y%m%d`.log 




test@]001:~/tmp/bla/mongo_script/logs$ cat log_file.log | awk -F"timezone = " '{print $2}' | awk -F" created_at" '{print $1}' | grep -v "^$" | sort | uniq -c | sort -rn

     42 America/Los_Angeles, locale = en_US,

     13 America/New_York, locale = en_US,

      3 America/Chicago, locale = en_US,

      2 undefined, locale = en_US,

      1 undefined, locale = undefined,

      1 Pacific/Honolulu, locale = en_US,

      1 Europe/Vienna, locale = de_AT,

      1 Europe/Rome, locale = en_US,

      1 Europe/London, locale = en_GB,

      1 Australia/Brisbane, locale = en_US,

      1 Asia/Tokyo, locale = en_US,

      1 Asia/Jakarta, locale = en_ID,

      1 America/Vancouver, locale = en_US,

      1 America/Vancouver, locale = en_CA,

      1 America/Edmonton, locale = en_CA,

      1 America/Detroit, locale = en_US,