0
点赞
收藏
分享

微信扫一扫

Cannot init client. Please provide correct options

三次方 2021-09-23 阅读 82

今天在将session存储到MongoDB里面的时候,需要使用一个connect-mongo中间件,配置好了之后一直报错,就很无奈



然后我使用了3的版本,使用了3的配置方法,解决了该问题。现在默认下载的是4.x的版本



3.x版本的配置方法
const session = require("express-session")
const MongoStore = require('connect-mongo')(session)
app.use(session({
  secret: "this is session",
  resave: false,
  saveUninitialized: true,
  name: "session.name",
  cookie: {
    secure: false,
    maxAge: 1000 * 60 * 60
  },
  rolling: true,

  // 主要是配置这个,url里面配置你的mongodb地址,端口号,数据库名称,默认会将session存储到sessions的集合下
  store: new MongoStore({
    url: 'mongodb://xxxxxxx:xxxxxx/xxxxxx',
    touchAfter: 24 * 3600 // 不管发出多少请求,在24小时内只更新一次session,除非session被修改
  })
}))
举报

相关推荐

0 条评论