本文主要是介绍connect-mongo使用简介,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
该模块用于将session存入mongo中
https://github.com/kcbanner/connect-mongo
使用方法:
app.use(express.session({secret: settings.cookie_secret,store: new MongoStore({db: settings.db})})); 配置说明:(下一行为上一行的翻译)
dbDatabase name OR fully instantiated node-mongo-native object- db 数据库名称
collectionCollection (optional, default:sessions)- collection 集合名称,默认为sessions
hostMongoDB server hostname (optional, default:127.0.0.1)- 数据库地址,默认为本机
portMongoDB server port (optional, default:27017)- 数据库端口,默认为27017
usernameUsername (optional)passwordPassword (optional)auto_reconnectThis is passed directly to the MongoDBServerconstructor as the auto_reconnect option (optional, default: false).sslUse SSL to connect to MongoDB (optional, default: false).urlConnection url of the form:mongodb://user:pass@host:port/database/collection. If provided, information in the URL takes priority over the other options.mongoose_connectionin the form:someMongooseDb.connections[0]to use an existing mongoose connection. (optional)stringifyIf true, connect-mongo will serialize sessions usingJSON.stringifybefore setting them, and deserialize them withJSON.parsewhen getting them. (optional, default: true). This is useful if you are using types that MongoDB doesn't support.
这篇关于connect-mongo使用简介的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!