Skip to content

Commit

Permalink
remove conn
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Dec 5, 2024
1 parent 26d9db6 commit a611f16
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/model/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ const Configuration = new Schema({
transport: String
});

function load(db) {
function load() {
Configuration.index({ apikey: 1, resource: 1, protocol: 1 }, { unique: true });
module.exports.model = db.model('Configuration', Configuration);
module.exports.model = mongoose.model('Configuration', Configuration);
module.exports.internalSchema = Configuration;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/model/Protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const Protocol = new Schema({
description: String
});

function load(db) {
function load() {
Protocol.index({ protocol: 1, resource: 1 }, { unique: true });
module.exports.model = db.model('Protocol', Protocol);
module.exports.model = mongoose.model('Protocol', Protocol);
module.exports.internalSchema = Protocol;
}

Expand Down
8 changes: 3 additions & 5 deletions lib/model/dbConn.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ const mongoose = require('mongoose');
const config = require('../utils/commonConfig');
const constants = require('../utils/constants');
const errors = require('../errors');
let defaultDb;
const DEFAULT_DB_NAME = 'iotagent-manager';

mongoose.Promise = global.Promise; // not including this causes DeprecationWarning

function loadModels() {
require('./Protocol').load(defaultDb);
require('./Configuration').load(defaultDb);
require('./Protocol').load();
require('./Configuration').load();
}

// Delay function for nodejs16
Expand Down Expand Up @@ -72,7 +71,7 @@ async function init(logger, host, db, port, username, password, options) {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
logger.info(`Attempt ${attempt}: Connecting to MongoDB at ${url}`);
defaultDb = await mongoose.connect(url, options);
await mongoose.connect(url, options);
logger.info('Successfully connected to MongoDB.');

// Register events
Expand Down Expand Up @@ -122,5 +121,4 @@ async function configureDb(logger) {
}

exports.configureDb = configureDb;
exports.db = defaultDb;
exports.DEFAULT_DB_NAME = DEFAULT_DB_NAME;

0 comments on commit a611f16

Please sign in to comment.