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

nodejs-mongodb-model

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodejs-mongodb-model - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

31

lib/MongodbModel.js

@@ -12,2 +12,3 @@

this.coll = coll;
this.collection_name = coll.collectionName;

@@ -43,7 +44,21 @@ // Write a wrapper "proxy", effectively a "catch all" to handle all methods

static init(url, dbName) {
this.url = url;
static connections = {};
static init(dbUrl, dbName) {
this.dbUrl = dbUrl;
this.dbName = dbName;
}
static async get_connection() {
this.connections = this.connections || {};
let dbUrl = this.dbUrl;
if(!this.connections[dbUrl]) {
let connectOptions = { useUnifiedTopology: true, useNewUrlParser: true };
this.connections[dbUrl] = await mongodb.MongoClient.connect(dbUrl, connectOptions);
}
this.connection = this.connections[dbUrl];
return this.connection;
}
static async model(coll_or_model_name) {

@@ -55,13 +70,11 @@ if(!coll_or_model_name) {

// const placement = this.get_placement(coll);
// const db = await this.get_db(placement);
// Connect
await this.get_connection();
let db_url = this.dbUrl;
// Get MongoDB Collection
let db_name = this.dbName;
let connectOptions = { useUnifiedTopology: true, useNewUrlParser: true };
this.connection = await mongodb.MongoClient.connect(db_url, connectOptions);
const db = this.connection.db(db_name);
const collection = db.collection(coll_name);
// Return Instance
return new MongodbModel(collection);

@@ -151,3 +164,3 @@ }

if(search_value) {
items[i][this.model_name] = indexed_items[search_value] || null;
items[i][this.collection_name] = indexed_items[search_value] || null;
}

@@ -154,0 +167,0 @@ }

{
"name": "nodejs-mongodb-model",
"version": "1.1.0",
"version": "1.2.0",
"description": "A thin Model around MongoDB collections with easy bulk, pagination and lookup operations",

@@ -5,0 +5,0 @@ "main": "index.js",

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