Class: Connection

Connection()

new Connection()

Represents a MongoDB connection and manages models associated with the connection.

Source:

Members

$models :Array.<Model>

An array containing instances of the Model class associated with the connection.

Type:
Source:

$mongoConnection :Db

The MongoDB connection instance.

Type:
  • Db
Source:

Methods

(static) checkAndReturnModelPath() → {string}

Static method to find and return the proper path to the models folder.

Source:
Returns:

The path to the models folder.

Type
string
Example
// Usage:
const modelPath = Connection.checkAndReturnModelPath();

(async, static) create(uriopt, modelPathopt, onConnectopt) → {Promise.<Connection>}

Static method to establish a connection to the MongoDB database.

Parameters:
Name Type Attributes Default Description
uri string <optional>
mongodb://127.0.0.1:27017/newapp

The URI of the MongoDB database.

modelPath string <optional>

The path to the folder containing model files.

onConnect function <optional>

Callback function to be called after connection.

Source:
Returns:
  • A promise that resolves to an instance of the Connection class.
Type
Promise.<Connection>

(static) sanitize(v) → {DefaultValue}

Static method to sanitize an object by removing properties with keys starting with '$'.

Parameters:
Name Type Description
v DefaultValue

The value to sanitize.

Source:
Returns:

The sanitized value.

Type
DefaultValue
Example
// Usage:
const sanitizedValue = Connection.sanitize({ $key: 'value', nested: { $property: 'nestedValue' } });