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.
| Modifier and Type | Field and Description |
|---|---|
protected String |
collection |
protected com.mongodb.DB |
db |
protected com.mongodb.DBCollection |
sessions |
protected int |
timeout |
| Constructor and Description |
|---|
MongoSessionStore(com.mongodb.DB db,
String collection,
int timeout) |
MongoSessionStore(com.mongodb.DB 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) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgenerateIDprotected final com.mongodb.DBCollection sessions
protected final int timeout
protected final String collection
protected final com.mongodb.DB db
public MongoSessionStore(com.mongodb.DB db,
String collection,
int timeout)
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 © 2015. All rights reserved.