How to set collection name in Mongoid for subclass?

class Foo include Mongoid::Document end class Bar < Foo end 

Foo.all returns Bars, and Bar.all returns Foos.

I want to put Foo and Bar in separate collections.

I tried

 class Bar < Foo store_in collection: 'bars' 

but got

 Mongoid::Errors::InvalidStorageParent: Problem: Invalid store_in call on class Bar. Summary: The :store_in macro can only be called on a base Mongoid Document 

Using Mongoid 4.0.2

+5
source share
1 answer

You also need to make Bar a Mongoid .

 class Bar < Foo include Mongoid::Document store_in collection: 'bars' 
+9
source

All Articles