Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@monti-apm/mongo-sharded-cluster
Advanced tools
Shard MongoDB in the app layer and build a MongoDB cluster
A simple way to shard MongoDB on the app layer.
With this approach, we have a set of replica sets. Then we can select a shard for our data based on free disk space on the DB.
For this, you need to run identical clusters (with the same size of disk space and the same storage engine)
Install it first:
npm i mongo-sharded-cluster
Using it
var MongoCluster = require('mongo-sharded-cluster');
var MongoClient = require('mongodb').MongoClient;
var async = require('async');
var myCluster = new MongoCluster();
var replSetUrls = [
{name: "one", url: "mongodb://localhost/one"},
{name: "two", url: "mongodb://localhost/two"},
];
async.each(replSetUrls, function(replSetInfo, done) {
MongoClient.connect(replSetInfo.url, function(err, db) {
if(db) {
myCluster.add(replSetInfo.name, db);
}
done(err);
});
}, function(err) {
if(err) {
throw err;
}
myCluster.startDbSizeLookup(function() {
// Pick a shard
var shardName = myCluster.pickShard();
// Then you can save this shardName in where you need.
// Get the connection for the shard
var conn = myCluster.getConnection(shardName);
});
});
You can use following helper method to initialize a cluster without hassle.
First make sure you have exports following env variables.
export MONGO_SHARD_URL_one=mongodb://localhost/one
export MONGO_SHARD_URL_two=mongodb://localhost/two
Then you can get initialize a cluster like this:
var MongoCluster = require('mongo-sharded-cluster');
MongoCluster.initFromEnv(function(err, cluster) {
if(err) {
throw err;
}
// do anything with the cluster
});
FAQs
Shard MongoDB in the app layer and build a MongoDB cluster
We found that @monti-apm/mongo-sharded-cluster demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.