- List all databases:
db.getMongo().getDBNames();
show databases
show dbs
- Change databases
use <DB_Name>
- List all collections
db.getCollectionNames() // returns an array
show collections // returns a clean output
installed mongoid with: gem install mongo
require 'mongo'
client = Mongo::Client.new([ '192.168.99.100:32776' ], :database => 'development_db')
c = client.database.collection_names
puts "\nAll Collections: #{c}\n"
customers = client[:customers] # Assume have array collection customers
# get all customers in an array format
c_array = customers.with(:read => { :mode => :primary_preferred }).find.to_a
puts "\ncustomers Array: #{c_array}\n"