nodejs-mongodb-model
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -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", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13601
319