Skip to content

Instantly share code, notes, and snippets.

@rinaldifonseca
Created July 15, 2012 20:42
Show Gist options
  • Save rinaldifonseca/3118546 to your computer and use it in GitHub Desktop.
Save rinaldifonseca/3118546 to your computer and use it in GitHub Desktop.
EM-Mongo with Goliath
config['mongo'] = EventMachine::Synchrony::ConnectionPool.new(size: 20) do
conn = EM::Mongo::Connection.new('localhost', 27017, 1, {:reconnect_in => 1})
conn.db('muisco')
end
require 'goliath'
require 'em-synchrony'
require 'em-synchrony/em-mongo'
# automatically parse the JSON HTTP response
class Track < Goliath::API
use Goliath::Rack::Params
use Goliath::Rack::Render, 'json'
use Goliath::Rack::JSONP
use Goliath::Rack::Validation::RequestMethod, %w(GET)
def response(env)
coll = mongo.collection('users')
res = coll.afind({}).to_a
payload = {:results => res}
[200, {}, payload]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment