Mongoid sessions not found

Sinatra Attempt | Mongoid 3. I run the following error whenever I try to save a database.

Mongoid::Errors::NoSessionsConfig: Problem: No sessions configuration provided. Summary: Mongoid configuration requires that you provide details about each session that can be connected to, and requires in the sessions config at least 1 default session to exist. Resolution: Double check your mongoid.yml to make sure that you have a top-level sessions key with at least 1 default session configuration for it. You can regenerate a new mongoid.yml for assistance via `rails g mongoid:config`. Example: development: sessions: default: database: mongoid_dev hosts: - localhost:27017 from /Users/rhodee/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-3.0.13/lib/mongoid/sessions/factory.rb:61:in `create_session' 

I have already confirmed the following:

  • Mongoid.yml file loaded
  • The hash contains the correct environment and db name

Pry returns the return value from the Mongoid.load! method Mongoid.load! :

 => {"sessions"=> {"default"=> {"database"=>"bluster", "hosts"=>["localhost:27017"], "options"=>{"consistency"=>"strong "}}}} 

If this helps, I added the app.rb file and the mongoid.yml file.

App.rb

 require 'sinatra' require 'mongoid' require 'pry' require 'routes' require 'location' configure :development do enable :logging, :dump_errors, :run, :sessions Mongoid.load!(File.join(File.dirname(__FILE__), "config", "mongoid.yml")) end 

Mongoid.yml

  development: sessions: default: database: bluster hosts: - localhost:27017 options: consistency: strong 
+4
source share
1 answer
 require 'sinatra' require 'mongoid' require 'pry' require 'routes' configure :development do enable :logging, :dump_errors, :run, :sessions Mongoid.load!(File.join(File.dirname(__FILE__), "config", "mongoid.yml")) end get '/db' do "db: " << Mongoid.default_session[:moped].database.inspect end 

I put together an example and it works great for me. Your problem is probably something else, like a configuration file with no read access or something else. In any case, my configuration file is identical to yours, and this is my sinatral file, and it works great.

0
source

Source: https://habr.com/ru/post/1447091/


All Articles