Cleiviane
Cleiviane

Reputation: 51

Get all database names with mongoid?

How can I get the name of all databases with Mongoid?

I found this:

connection = Mongoid.master.connection 
connection.database_names

but it is not working. It turns out this error: undefined method master 'for Mongoid: Module (NoMethodError)

Any help?

Upvotes: 0

Views: 210

Answers (1)

Cleiviane
Cleiviane

Reputation: 51

I got with moped. Maybe it is not the best way, but it is working for me.

session = Moped::Session.new(["127.0.0.1:27017"])
databases = session.databases.first[1]

Upvotes: 1

Related Questions