
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
db-client-smacondi
Advanced tools
A Node client for managing database connections and account-based cluster routing, designed for MongoDB
A Node.js client for managing database connections and account-based cluster routing, designed for MongoDB.
npm install db-client-smacondi
// import named exports
import { getDbClientSmacondi, closeAllDbClients } from 'db-client-smacondi';
// Using the singleton pattern (recommended)
const dbClientSmacondi = getDbClientSmacondi(connectionStringMap, apiURL, readTimeout, writeTimeout);
// load dbClient for an account (async):
const { dbClient, dbName, _id } = await dbClientSmacondi.getDbClientByAccountId('someAccountId')
// or load a dbClient by providing a clusterId (sync)
const clusterDbClient = dbClientSmacondi.getDbClientByClusterId('someClusterId')
// Close all database connections when needed
await closeAllDbClients();
// import named exports
const { getDbClientSmacondi, closeAllDbClients } = require('db-client-smacondi');
// Using the singleton pattern (recommended)
const dbClientSmacondi = getDbClientSmacondi(connectionStringMap, apiURL, readTimeout, writeTimeout);
// load dbClient for an account (async):
const { dbClient, dbName, _id } = await dbClientSmacondi.getDbClientByAccountId('someAccountId')
// or load a dbClient by providing a clusterId (sync)
const clusterDbClient = dbClientSmacondi.getDbClientByClusterId('someClusterId')
// Close all database connections when needed
await closeAllDbClients();
function that returns a singleton instance of the DbClientSmacondi class.
{Object<string, string>}
: Object where key is the clusterId and value is the connection string for the cluster.{string}
(optional): URL of the account API to get account details. Default: 'localhost:5000'.{number}
(optional): Read timeout in milliseconds. Default: 30000.{number}
(optional): Write timeout in milliseconds. Default: 30000.Returns: {DbClientSmacondi}
- The DbClientSmacondi singleton instance.
Closes all active database client connections.
Returns: {Promise<void>}
Low-level class for direct MongoDB client management.
{string}
: MongoDB connection string.{number}
(optional): Read timeout in milliseconds. Default: 30000.{number}
(optional): Write timeout in milliseconds. Default: 30000.import { getDbClientSmacondi } from 'db-client-smacondi';
// Configure your cluster connection strings
const connectionStringMap = {
'cluster1': 'mongodb://user:pass@host1:port/db',
'cluster2': 'mongodb://user:pass@host2:port/db',
};
// Initialize the client
const dbClientSmacondi = getDbClientSmacondi(connectionStringMap, 'https://api.example.com/accountInfo', 30000, 30000);
// Use the client in your application
async function main() {
try {
// Get a database client for a specific account
const { dbClient, dbName, _id } = await dbClientSmacondi.getDbClientForAccount('demo_account');
// Perform database operations
const collection = await dbClient.find(dbName, 'collection_a', {});
console.log(result);
} catch (error) {
console.error('Error:', error);
} finally {
// Close all connections when your app is shutting down
await closeAllDbClients();
}
}
This package is licensed under the AGPL-3.0-or-later license.
FAQs
A Node client for managing database connections and account-based cluster routing, designed for MongoDB
We found that db-client-smacondi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.