mongoid3 - Mongoid Identity Map setting not taking effect in Rails console -
it not appear identity_map
setting getting picked config/mongoid.yml
file.
here's file:
development: sessions: default: uri: mongodb://localhost:27017/test_development options: &defaultopts op_timeout: 60 allow_dynamic_fields: false identity_map_enabled: true preload_models: true raise_not_found_error: false
when run through rails_env=development rails console
map not turned on:
$ rails_env=development rails c loading development environment (rails 3.2.13) [1] pry(main)> mongoid.using_identity_map? => false [2] pry(main)> mongoid.identity_map_enabled? => false
even attempt manually load mongoid
, file doesn't change it:
[3] pry(main)> require 'mongoid' => false [4] pry(main)> mongoid.load!("./config/mongoid.yml") => {"sessions"=> {"default"=> {"uri"=>"mongodb://localhost:27017/test_development", "options"=> {"op_timeout"=>60, "allow_dynamic_fields"=>false, "identity_map_enabled"=>true, "preload_models"=>true, "raise_not_found_error"=>false}}}} [5] pry(main)> mongoid.using_identity_map? => false [6] pry(main)> mongoid.identity_map_enabled? => false
only if manually set value take affect:
[8] pry(main)> mongoid.identity_map_enabled = true => true [9] pry(main)> mongoid.using_identity_map? => true [10] pry(main)> mongoid.identity_map_enabled? => true
why setting not being loaded correctly?
this issue happening using rails 3.2.13 , mongoid 3.1.2.
:options
shouldn't nested in :default
. mongoid expecting see mongoid.yml
in format:
development: sessions: default: uri: mongodb://localhost:27017/test_development options: op_timeout: 60 allow_dynamic_fields: false identity_map_enabled: true preload_models: true raise_not_found_error: false
see source :options
being loaded.
$ pry [1] pry(main)> require 'mongoid' => true [2] pry(main)> mongoid.load!("./mongoid.yml", :production) => {"sessions"=> {"default"=>{"database"=>"mongoid_prod", "hosts"=>["localhost:27017"]}}, "options"=>{"identity_map_enabled"=>true, "include_root_in_json"=>true}} [3] pry(main)> mongoid.using_identity_map? => true [4] pry(main)>
edit: pointed out @cbmanica, there multiple places options
can set. example have:
development: sessions: default: uri: mongodb://localhost:27017/test_development options: consistency: :strong options: op_timeout: 60
for options
set on mongodb database, cannot nested inside of session
. see source defaults.
Comments
Post a Comment