猫鼬和连接-mongo
Mongoose and connect-mongo
我正在使用 mongoose 来管理数据之间的关系,并且我正在尝试使用 connect-mongo 在数据库中存储特定会话。
看来我们需要两次连接到数据库,一次使用 mongoose,另一次使用 connect-mongo.
我正在使用以下代码为 mongoose
初始化连接
await mongoose.connect(this._connectionUrl, this._connectionOptions);
每次都初始化一个新商店(不确定我关于代码初始化是否正确)。
app.use(session({
// secret: config.sessionSecretKey,
secret: "secretkey",
resave: true,
saveUninitialized: true,
cookie: { maxAge: 19 * 60000 }, // store for 19 minutes
store: MongoStore.create({
mongoUrl: this._connectionUrl,
mongoOptions: this._connectionOptions // See below for details
})
}))
有什么方法可以将连接从 mongoose 传递到 mongo-connect Store?
我也在寻找解决方案,只是在 connect-mongo
的“迁移指南”上阅读了这个
For the options, you should make the following changes:
Change url to mongoUrl Change collection to collectionName if you are
using it Keep clientPromise if you are using it mongooseConnection has
been removed. Please update your application code to use either
mongoUrl, client or clientPromise To reuse an existing mongoose
connection retreive the mongoDb driver from you mongoose connection
using Connection.prototype.getClient() and pass it to the store in the
client-option. Remove fallbackMemory option and if you are using it,
还有这个例子https://github.com/jdesboeufs/connect-mongo/blob/master/example/mongoose.js
我正在使用 mongoose 来管理数据之间的关系,并且我正在尝试使用 connect-mongo 在数据库中存储特定会话。
看来我们需要两次连接到数据库,一次使用 mongoose,另一次使用 connect-mongo.
我正在使用以下代码为 mongoose
初始化连接await mongoose.connect(this._connectionUrl, this._connectionOptions);
每次都初始化一个新商店(不确定我关于代码初始化是否正确)。
app.use(session({
// secret: config.sessionSecretKey,
secret: "secretkey",
resave: true,
saveUninitialized: true,
cookie: { maxAge: 19 * 60000 }, // store for 19 minutes
store: MongoStore.create({
mongoUrl: this._connectionUrl,
mongoOptions: this._connectionOptions // See below for details
})
}))
有什么方法可以将连接从 mongoose 传递到 mongo-connect Store?
我也在寻找解决方案,只是在 connect-mongo
的“迁移指南”上阅读了这个For the options, you should make the following changes:
Change url to mongoUrl Change collection to collectionName if you are using it Keep clientPromise if you are using it mongooseConnection has been removed. Please update your application code to use either mongoUrl, client or clientPromise To reuse an existing mongoose connection retreive the mongoDb driver from you mongoose connection using Connection.prototype.getClient() and pass it to the store in the client-option. Remove fallbackMemory option and if you are using it,
还有这个例子https://github.com/jdesboeufs/connect-mongo/blob/master/example/mongoose.js