MongoService
Name | MongoService |
Class Path |
|
Versions | 11 |
Overview
The MongoService interface defines methods for interacting with a MongoDB instance with TTL (Time-To-Live) support. It is not intended to be instantiated or imported directly. The functions it defines are exposed in the TrustBuilder scripting environment through the global tb object. These functions provide basic operations to store and retrieve values with an expiration mechanism.
Available Functions
Use tb.mongoTTLWrite and tb.mongoTTLRead to interact with MongoDB with TTL support:
void mongoTTLWrite(String key, String value, int ttl)
Stores a key-value pair in MongoDB with a specified TTL (Time-To-Live).
Parameters:
key(String): The unique identifier for the value.value(String): The data to be stored.ttl(int, optional): Time in seconds before the entry expires. Default value: 300 seconds.
String mongoTTLRead(String key)
Retrieves a stored value based on the given key.
Parameters:
key(String): The unique identifier of the stored value.
Returns:
String: The retrieved value ornullif the key does not exist or has expired.
Summary
The MongoService functions provide an abstraction for managing temporary data in MongoDB using TTL. It allows:
Writing key-value pairs with an expiration time.
Retrieving values before they expire.
This is particularly useful for session management, caching, and temporary storage scenarios in applications that require MongoDB persistence.
Attempting to instantiate MongoServicewill fail with a NoSuchMethodException. Always use the tb object.