how to have separate keys per record in mongo_mapper + Rails
- by Vitaly Kushner
When I'm adding a record in mongodb I can specify whatever keys I want and it will store it in the db. The problem is that it will remember those keys for the next time I insert another record. so for example if I do the following:
Product.create :foo => 123
and then
Product.create :bar => 456
I get :foo => nil field in the 2nd record.
This is definitely not a limitation of mongodb itself, since if I restart the rails console and create yet another record with different set of columns, it will not add the columns from the 1st 2 records.
So it seems like mongomapper remembers all the keys used and inserts them all into all records, even if values are not provided.
The question is obviously: how do I disable this crazy attributes explosion?
Basically I want only the 'permanent' keys that I specify in the model to be in every record, but all the 'extra' attributes to be specified per record and not to mess the consequent records.