
Research
/Security News
9 Malicious NuGet Packages Deliver Time-Delayed Destructive Payloads
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.
mongo-client-connect
Advanced tools
Provides an easy way to specify N collections from N connectionURIs to be retrieved at once, in one call (DRY!). It reuses the same connection objects (creating only one connection pool per connectionURI) and collection instances, avoiding the creation of
Provides an easy way to specify N collections from N connectionURIs to be retrieved at once, in one call (DRY!). It reuses the same connection objects (creating only one connection pool per connectionURI) and collection instances, avoiding the creation of many, unnecessary, connections pools to a same connectionURI.
npm install mongo-client-connect
OBS: Examples are created for Nodejs v6+ (Destructuring!).
A simple connection to a MongoDB
MongoClientConnect('mongodb://localhost/dbName').then(db => {});
But in case you have more than one call in your project:
// Somewhere
MongoClientConnect('mongodb://localhost/dbName').then(db => {});
//[...]
// Somewhere else...
MongoClientConnect('mongodb://localhost/dbName').then(db => {});
by mistake, or intentionally because of by some file structure strategy, only one connection pool will be created
A simple connection to N MongoDBs
MongoClientConnect([
'mongodb://localhost/dbName1',
'mongodb://anotherHost/dbName2'
]).then(([ db1, db2 ]) => {
console.log(db1.databaseName);
console.log(db2.databaseName);
});
Array)It will connect and return the collections that has been asked for.
MongoClientConnect('mongodb://localhost/dbName', [
'dbCollectionName1',
'dbCollectionName2'
])
.then( ([ dbCollectionName1, dbCollectionName2 ]) => {
// Example of something with one collection
dbCollectionName1.find({}).toArray().then(docs => console.log(docs.length));
// Example of something with the other collection
dbCollectionName2.find({}).toArray().then(docs => console.log(docs.length));
});
Object)It will connect and return collections, the same as above, but the collections are specified by an Object, in case you need to define collections alias for your code.
MongoClientConnect('mongodb://localhost/dbName', { someAlias: 'dbCollectionName' })
.then(({ someAlias }) => {
// 'someAlias' will be a reference to collection 'dbCollectionName'
someAlias.find({}).toArray().then(r => console.log(r.length))
});
Array)It connects to N MongoDBs and returns collections for each of them.
MongoClientConnect({
'mongodb://localhost/dbName': ['dbCollectionName1'],
'mongodb://someOtherHost/dbName': ['dbCollectionName2', 'dbCollectionName3']
})
.then(([[ dbCollectionName1 ], [ dbCollectionName2, dbCollectionName3 ]]) => {
console.log(dbCollectionName1.s.dbName, dbCollectionName2.s.dbName, dbCollectionName3.s.dbName);
})
Object)Same as above, it connects to N MongoDBs and returns collections for each of them, but defining collections as an Object in case you need to define collections alias.
MongoClientConnect({
'mongodb://localhost/dbName': {
alias1: 'dbCollectionName1'
},
'mongodb://someOtherHost/dbName': {
alias2: 'dbCollectionName2',
alias3: 'dbCollectionName3'
}
})
.then(([{ alias1 }, { alias2, alias3 }]) => {
console.log(alias1.s.name, alias2.s.name, alias3.s.name);
});
FAQs
It reuses the same connection objects (creating only one connection pool per connectionURI) and collection instances, avoiding the creation of many, unnecessary, connections pools to a same connectionURI. Also provides an easy way to specify N collections
The npm package mongo-client-connect receives a total of 0 weekly downloads. As such, mongo-client-connect popularity was classified as not popular.
We found that mongo-client-connect 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.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.