Collection Session Storage

const collectionStorage = require('@arangodb/foxx/sessions/storages/collection');

The collection session storage persists sessions to a collection in the database.

Creating a storage

collectionStorage(options): Storage

Creates a Storage that can be used in the sessions middleware.

Arguments

  • options: Object

An object with the following properties:

  • collection: ArangoCollection

The collection that should be used to persist the sessions.If a string is passed instead of a collection it is assumed to be the fullyqualified name of a collection in the current database.

  • ttl: number (Default: 60 * 60)

The time in seconds since the last update until a session will beconsidered expired.

  • pruneExpired: boolean (Default: false)

Whether expired sessions should be removed from the collection when theyare accessed instead of simply being ignored.

  • autoUpdate: boolean (Default: true)

Whether sessions should be updated in the collection every time theyare accessed to keep them from expiring. Disabling this optionwill improve performance but means you will have to take care ofkeeping your sessions alive yourself.

If a string or collection is passed instead of an options object, it willbe interpreted as the collection option.

prune

storage.prune(): Array<string>

Removes all expired sessions from the collection. This method should be calledeven if the pruneExpired option is enabled to clean up abandoned sessions.

Returns an array of the keys of all sessions that were removed.

save

storage.save(session): Session

Saves (replaces) the given session object in the collection. This method needsto be invoked explicitly after making changes to the session or the changeswill not be persisted. Assigns a new _key to the session if it previouslydid not have one.

Arguments

  • session: Session

A session object.

Returns the modified session.

clear

storage.clear(session): boolean

Removes the session from the collection. Has no effect if the session wasalready removed or has not yet been saved to the collection (i.e. has no _key).

Arguments

  • session: Session

A session object.

Returns true if the session was removed or false if it had no effect.