Ankur
Ankur

Reputation: 61

Node.js Getting Error when saving session in database, Sails.js using sails-mongo module?

i have gone through the sails doc http://sailsjs.org/documentation/reference/configuration/sails-config-session db configuration is

  adapter: 'sails-mongo',
  host: 'localhost',
  port: 27017,
  db: 'sails',
  collection: 'sessions',

Getting error -->

A hook (session) failed to load! error: Could not load Connect session adapter :: sails-mongo installed "sails-mongo" by using npm install sails-mongo

Upvotes: 2

Views: 527

Answers (1)

Gustavo Garcia
Gustavo Garcia

Reputation: 3243

Sails.js uses a different connector for sessions, that is why you are having this problem. All you need to do is install and configure the connect-mongo package to use the same mongodb configured for your data:


You need to run install connect-mongo using npm:

npm install --save connect-mongo

Also, you nees to configure the session adapter in the config/session.js file. And it uses a different format:

// Note: user, pass and port are optional
url: 'mongodb://user:pass@host:port/database',
collection: 'sessions',
auto_reconnect: false,
ssl: false,
stringify: true

All this information is available on this page of the docs: Sails.js session Documentation

Upvotes: 1

Related Questions