public class MongoSessionStore extends Object implements Session.Store
Session.Store powered by
Mongodb.
{
use(new Mongodb());
session(MongoSessionStore.class);
get("/", req -> {
req.session().set("name", "jooby");
});
}
The name attribute and value will be stored in a
Mongodb.
By default, a mongodb session will expire after 30 minutes. Changing the default
timeout is as simple as:
# 8 hours session.timeout = 8h # 15 seconds session.timeout = 15 # 120 minutes session.timeout = 120m
It uses MongoDB's TTL collection feature (2.2+) to have mongod automatically remove
expired sessions.
-1.
Default mongodb collection is sessions.
It's possible to change the default key setting the mongodb.sesssion.collection
properties.
rnd| Constructor and Description |
|---|
MongoSessionStore(com.mongodb.client.MongoDatabase db,
String collection,
long timeoutInSeconds) |
MongoSessionStore(com.mongodb.client.MongoDatabase db,
String collection,
String timeout) |
| Modifier and Type | Method and Description |
|---|---|
void |
create(Session session) |
void |
delete(String id) |
Session |
get(Session.Builder builder) |
void |
save(Session session) |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgenerateIDpublic MongoSessionStore(com.mongodb.client.MongoDatabase db,
String collection,
long timeoutInSeconds)
public Session get(Session.Builder builder)
get in interface Session.Storepublic void save(Session session)
save in interface Session.Storepublic void create(Session session)
create in interface Session.Storepublic void delete(String id)
delete in interface Session.StoreCopyright © 2017. All rights reserved.