Skip to content

Instantly share code, notes, and snippets.

@jaydestro
Created June 12, 2018 18:02
Show Gist options
  • Save jaydestro/cc8ec65d5ada81dd027f6e7f30f2c22d to your computer and use it in GitHub Desktop.
Save jaydestro/cc8ec65d5ada81dd027f6e7f30f2c22d to your computer and use it in GitHub Desktop.
ruby and mongodb
require 'mongo' # requires mongoid to be installed
Mongo::Logger.logger.level = ::Logger::FATAL # provides logging output for fails
client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'hackathon') # establishes database connection to localhost, database name hackathon
client.collections.each { |coll| puts coll.name } # does a loop on listing each collection in database and then prints them to standard out
client.close # closes database connection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment