From d7acc12b7edf76323d1fbc03c8d5962a6fab223c Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Mon, 5 Feb 2024 06:22:56 +0100 Subject: [PATCH] allow passing DB/Collection to MongoSessionStore --- mongodb/vibe/db/mongo/sessionstore.d | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/mongodb/vibe/db/mongo/sessionstore.d b/mongodb/vibe/db/mongo/sessionstore.d index 55f46e298a..f4c371cb09 100644 --- a/mongodb/vibe/db/mongo/sessionstore.d +++ b/mongodb/vibe/db/mongo/sessionstore.d @@ -52,7 +52,6 @@ final class MongoSessionStore : SessionStore { Params: url = URL of the MongoDB database (e.g. `"mongodb://localhost/mydb"`) - database = Name of the database to use collection = Optional collection name to store the sessions in */ this(string url, string collection = "sessions") @@ -66,6 +65,27 @@ final class MongoSessionStore : SessionStore { m_sessions = db[collection]; } + /** Constructs a new MongoDB session store using an existing DB. + + Params: + db = the connected MongoDB database. + collection = the collection name for the sessions collection. + */ + this(MongoDatabase db, string collection = "sessions") + { + m_sessions = db[collection]; + } + + /** Constructs a new MongoDB session store using a collection object. + + Params: + collection = the collection to store sessions in. + */ + this(MongoCollection collection) + { + m_sessions = collection; + } + /** The duration without access after which a session expires. */ @property Duration expirationTime() const { return m_expirationTime; }