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)
Delete a session by ID.
|
Session |
get(Session.Builder builder)
Get a session by ID (if any).
|
void |
save(Session session)
Save/persist a 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)
Session.Store
get in interface Session.Store
builder - A session builder.
null.
public void save(Session session)
Session.Store
save in interface Session.Store
session - A session to be persisted.
public void create(Session session)
create in interface Session.Store
public void delete(String id)
Session.Store
delete in interface Session.Store
id - A session ID.
Copyright © 2019. All rights reserved.