I have different sessions in my mongoid.yml
, where one session provides data from a static mongo database. I was wondering if it is possible, to "load" a session in read only mode, so that no changes with save
, create
, destroy
or destroy_all
can be made. My mongoid.yml
looks like this:
production:
sessions:
default:
database: my_app_production
hosts:
- localhost:27017
options:
read: primary
static_content:
database: static_content_db
hosts:
- localhost:27017
options:
read: primary
options:
use_utc: true
I have special models for the static_content
session, they look like this:
class StaticMappings
include Mongoid::Document
include Mongoid::Attributes::Dynamic
store_in collection: "static_mappings", session: "static_content"
end
I want to prevent myself form accidentially calling things like StaticMappings.destroy_all
or a StaticMappings.create(...)
. Is this possible?
I found this Making an entire model read-only with Mongoid, but this won't prevent someone from calling create
or destroy
on a model instance.