Client
Overview
Module
- package:
org.eclipse.dirigible.sdk.mongodb - source: mongodb/Client.java
Hands back a configured Mongo MongoClient (com.mongodb.client.MongoClient). Callers can address any database / collection on it directly and use the full MongoDB driver surface — aggregation pipelines, multi-document transactions, GridFS, change streams.
getDefaultDatabaseName() returns the database name configured in the platform properties (often the entry point for application-managed collections); createBasicDBObject() returns a fresh empty DBObject for callers that still use the legacy DBObject API.
Key Features:
- Raw MongoClient: Returns the standard
com.mongodb.client.MongoClientso callers can use the full driver surface. - Default Database:
getDefaultDatabaseName()exposes the database name from the platform configuration. - Legacy DBObject Factory:
createBasicDBObject()returns an emptyDBObjectfor code paths still using the legacy API. - Connection parameters: Accepts a URI, user, and password — pass
nullto fall back to the platform defaults.
Example Usage:
import org.eclipse.dirigible.sdk.mongodb.Client;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.MongoCollection;
import org.bson.Document;
MongoClient client = Client.getClient(null, null, null);
MongoDatabase db = client.getDatabase(Client.getDefaultDatabaseName());
MongoCollection<Document> orders = db.getCollection("orders");
orders.insertOne(new Document("orderId", "O-1001").append("status", "NEW"));Methods
getClient()
Returns a configured MongoClient. If uri is null the platform default URI is used; the same applies to user and password.
javapublic static MongoClient getClient(String uri, String user, String password);
Parameter Type Description uriStringThe MongoDB connection URI, or nullto use the platform default.userStringThe MongoDB user, or nullto use the platform default.passwordStringThe MongoDB password, or nullto use the platform default.Returns
- Type:
com.mongodb.client.MongoClient- Description: A connected MongoDB client ready for use against any database / collection.
getDefaultDatabaseName()
Returns the default MongoDB database name from the platform configuration. Use this when an application does not need to switch between multiple databases.
javapublic static String getDefaultDatabaseName();Returns
- Type:
String- Description: The configured default database name.
createBasicDBObject()
Returns a fresh empty legacy DBObject. Useful for code paths still working with the pre-Document driver API.
javapublic static DBObject createBasicDBObject();Returns
- Type:
com.mongodb.DBObject- Description: A new empty
BasicDBObject.