tbbooher / journal

0 stars 0 forks source link

replace all dates on server with the new format #8

Closed tbbooher closed 9 years ago

tbbooher commented 9 years ago

run this on the server:

https://gist.github.com/tbbooher/85a299b66123ffff032d

#!/Users/christinebooher/.rvm/rubies/ruby-2.2.1/bin/ruby

require 'mongo'

Mongo::Logger.logger.level = ::Logger::FATAL

entries = Mongo::Client.new('mongodb://127.0.0.1:3001/meteor')["entries"]

#entries = client["entries"]

dates = entries.find.map{|e| e[:entry_date]}

dates.each do |d|
  new_date = d.gsub(/(\d+)\-(\d+)\-(\d+)/) {"#{$2}/#{$3}/#{$1}"}
  puts "replacing #{entries.find({:entry_date => d}).first[:entry_date]} with #{new_date}" # .update_one("$set" => {:entry_date => new_date})
  entries.find({:entry_date => d}).update_one("$set" => {:entry_date => new_date})
end
tbbooher commented 9 years ago

works . .

require 'mongo'

Mongo::Logger.logger.level = ::Logger::FATAL

entries = Mongo::Client.new('mongodb://user_name:password@127.0.0.1:27017/journal')["entries"]

puts "about to work #{entries.find.count} entries"

#entries = client["entries"]

dates = entries.find.map{|e| e[:entry_date]}

# puts dates

dates.each do |d|
  if d.nil?
    puts "nil value: #{d.inspect}"
  else
    new_date = d.gsub(/(\d+)\-(\d+)\-(\d+)/) {"#{$2}/#{$3}/#{$1}"}
    puts "replacing #{entries.find({:entry_date => d}).first[:entry_date]} with #{new_date}" # .update_one("$set" => {:entry_date => new_date})
    entries.find({:entry_date => d}).update_one("$set" => {:entry_date => new_date})
  end
end