Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

native-mongo-util

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

native-mongo-util - npm Package Compare versions

Comparing version 2.3.2 to 3.0.0

tunnel.js

22

index.js

@@ -8,3 +8,3 @@ const Log = require('logger3000').getLogger(__filename);

const MONGO_URL = process.env.MONGO_URL || 'mongodb://localhost/test';
const { get } = require('./tunnel');
/**

@@ -36,3 +36,3 @@ * Class to create native Mongo connection

*/
this.getCollection = memoize(collectionName => {
this.getCollection = memoize((collectionName) => {
this.checkAndThrowDBNotConnectedError();

@@ -56,2 +56,3 @@ return this._db.collection(collectionName);

* Connects to mongodb for the provided `mongoURL` for this connection instance
* @param {Object} [options] - MongoDB connection options
* @public

@@ -61,3 +62,3 @@ * @returns {Promise<DB>} - Mongodb DB instance.

*/
async connect() {
async connect(options = {}) {
if (this.isConnecting) {

@@ -73,11 +74,10 @@ Log.debug({ msg: 'connecting to DB' });

loggerLevel: 'info',
useNewUrlParser: true
useNewUrlParser: true,
};
this.isConnecting = true;
this._client = await MongoClient.connect(this._mongoURL, {
...this._options,
...fixOpts
});
await get();
this._client = await MongoClient.connect(this._mongoURL, { ...this._options, ...fixOpts, ...options });
this._db = this._client.db();

@@ -170,3 +170,3 @@

*/
exports.connect = options => {
exports.connect = (options) => {
if (_defaultConnection) {

@@ -187,3 +187,3 @@ throw new Error(`Already connected to ${_defaultConnection.getDBName()}, Try \`newConnection()\` instead.`);

*/
exports.close = async force => {
exports.close = async (force) => {
const result = await _defaultConnection.close(force);

@@ -219,3 +219,3 @@

*/
exports.getCollection = collectionName => _defaultConnection.getCollection(collectionName);
exports.getCollection = (collectionName) => _defaultConnection.getCollection(collectionName);

@@ -222,0 +222,0 @@ /**

{
"name": "native-mongo-util",
"version": "2.3.2",
"version": "3.0.0",
"description": "",

@@ -8,4 +8,4 @@ "main": "index.js",

"test": "ava test.js",
"lint": "eslint index.js",
"format": "prettier --write 'index.js'"
"lint": "eslint index.js tunnel.js",
"format": "prettier --write '{index.js,tunnel.js}'"
},

@@ -24,20 +24,21 @@ "repository": {

"dependencies": {
"bluebird": "^3.5.5",
"bluebird": "^3.7.2",
"tunnel-ssh": "^4.1.4",
"logger3000": "0.1.1",
"memoizee": "^0.4.14",
"mongodb": "^3.2.7",
"mongodb": "^3.5.7",
"then-sleep": "^1.0.1"
},
"devDependencies": {
"ava": "^2.1.0",
"babel-eslint": "^10.0.2",
"eslint": "^6.0.1",
"ava": "^3.6.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.8.0",
"eslint-config-lil": "^1.0.6",
"eslint-config-prettier": "^6.0.0",
"eslint-config-xo-space": "^0.21.0",
"eslint-plugin-prettier": "^3.1.0",
"eslint-config-prettier": "^6.10.1",
"eslint-config-xo-space": "^0.24.0",
"eslint-plugin-prettier": "^3.1.2",
"event-stream": ">=4.0.1",
"nodemon": "^1.19.1",
"prettier": "^1.18.2"
"nodemon": "^2.0.2",
"prettier": "^2.0.4"
}
}
# native-mongo-util
Utility package to connect multiple mongo databases.
Utility package to connect multiple mongo databases. Supports SSH tunneling.

@@ -69,2 +69,10 @@ ## Usage

## Environment Variables
- `MONGO_URL` Mongo connection url
- `SSH_HOST` ssh hostname or ip
- `SSH_USER` ssh user for remote connection
- `SSH_PASSWORD` ssh connection password
- `SSH_KEY_PATH` ssh private key path like `~/.ssh/id_rsa`. Either of `SSH_PASSWORD` or `SSH_KEY_PATH` must be provided depending on remote server auth mode.
[![Build Status](https://travis-ci.org/saggiyogesh/native-mongo-util.svg?branch=master)](https://travis-ci.org/saggiyogesh/native-mongo-util)
process.env.MONGO_URL = 'mongodb://localhost/testDB';
process.env.NODE_ENV = 'production';
import test from 'ava';
const test = require('ava');
const { getDBName, connect, getCollection, newConnection, getClient } = require('./');
const opts = { poolSize: 20 };
test.serial('check connection with mongodb', async t => {
test.serial('check connection with mongodb', async (t) => {
await connect(opts);

@@ -17,3 +18,3 @@ const dbName = getDBName();

test.serial('fetch all records from a collection', async t => {
test.serial('fetch all records from a collection', async (t) => {
const d = Date.now();

@@ -25,3 +26,3 @@ await getCollection('testCol').insert({ d });

test.serial('another mongo connection', async t => {
test.serial('another mongo connection', async (t) => {
const mongoURL = 'mongodb://localhost/someDB';

@@ -40,3 +41,3 @@ const connection = newConnection(mongoURL, opts);

test.serial('validate options passed to mongo client for default connection', async t => {
test.serial('validate options passed to mongo client for default connection', async (t) => {
const client = await getClient();

@@ -46,5 +47,5 @@ t.is(opts.poolSize, client.s.options.poolSize);

test.serial('validate options passed to mongo client for other connection', async t => {
test.serial('validate options passed to mongo client for other connection', async (t) => {
const client = await getClient();
t.is(opts.poolSize, client.s.options.poolSize);
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc