Skip to content

Instantly share code, notes, and snippets.

@D3MZ
Last active December 11, 2015 03:58
Show Gist options
  • Save D3MZ/4541747 to your computer and use it in GitHub Desktop.
Save D3MZ/4541747 to your computer and use it in GitHub Desktop.
Export Mongo to AWS Cloud Search
require 'mongo'
require 'pp'
require 'json'
class HaystackDB
include Mongo
def initialize
mongo = MongoClient.new('localhost', 27017)['twitter']
@whois = mongo['whois']
end
def normalize u
u = u["attrs"] unless u["screen_name"]
hash = Hash.new{|h,k| h[k]=Hash.new(&h.default_proc) }
hash["name"] = u["name"]
hash["user"] = u["id"]
hash["screen_name"] = u["screen_name"]
hash["utc_offset"] = u["utc_offset"]
hash["location"] = u["location"]
hash["description"] = u["description"]
hash["created_at"] = u["created_at"]
hash["lang"] = u["lang"]
hash["status"]["created_at"] = u["status"]["created_at"] if u["status"]
hash
end
def normalize_json user
normalize(user).to_json
end
def to_aws_test
user_json = normalize_json @whois.find_one()
#aws endpoint here
end
def to_aws
@whois.find.collect do |user|
user_json = normalize_json user
#aws endpoint here
end
end
end
db = HaystackDB.new
pp db.to_aws_test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment