How to programmatically get the current database Mongoid is writing to?

mongodb, mongodb-ruby, mongoid, mongoid3, ruby-on-rails

Solution

Got it!

Mongoid.default_session.options[:database]

Problem

I am talking to multiple databases using Mongoid.override_database("database_name") using Mongoid with rails. How do I find the current database programmatically? Mongoid docs on sessions: http://mongoid.org/en/moped/docs/driver.html define methods to override database but do not define a way to get the current database in use.

Original source