Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all Mongoid models in Rails console

I want to list all the models which have a respective collection in my mongodb database? I'm using mongoid gem for for MongoDB.

I would try something like this

ActiveRecord::Base.send :subclasses which works fine, but I'm not using ActiveRecord.

like image 374
Kumar Avatar asked Apr 27 '16 13:04

Kumar


1 Answers

There's Mongoid::Config#models:

Get all the models in the application - this is everything that includes Mongoid::Document.

All Config methods can be accessed from the Mongoid module, so you can call:

Mongoid.models #=> [...]
like image 111
Stefan Avatar answered Nov 16 '22 10:11

Stefan