@frogfish/k2db 1.0.11 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/db.js +7 -13
  2. package/package.json +1 -1
package/db.js CHANGED
@@ -19,32 +19,26 @@ class K2DB {
19
19
  */
20
20
  async init() {
21
21
  const dbName = this.conf.name;
22
- let connectUrl = "mongodb://";
22
+ let connectUrl = "mongodb+srv://"; // Use SRV connection prefix
23
23
  // Add user and password if available
24
24
  if (this.conf.user && this.conf.password) {
25
25
  connectUrl += `${encodeURIComponent(this.conf.user)}:${encodeURIComponent(this.conf.password)}@`;
26
26
  }
27
- // Handle single host (non-replicaset) or multiple hosts (replicaset)
27
+ // Add the host
28
28
  if (!this.conf.hosts || this.conf.hosts.length === 0) {
29
29
  throw new k2error_1.K2Error(k2error_1.ServiceError.CONFIGURATION_ERROR, "No valid hosts provided in configuration", "sys_mdb_no_hosts");
30
30
  }
31
- connectUrl += this.conf.hosts
32
- .map((host) => `${host.host}:${host.port || 27017}`)
33
- .join(",");
34
- // Append database name
35
- connectUrl += `/${dbName}`;
36
- // Append replicaset and options if it's a replicaset
37
- if (this.conf.hosts.length > 1 && this.conf.replicaset) {
38
- connectUrl += `?replicaSet=${this.conf.replicaset}&keepAlive=true&autoReconnect=true&socketTimeoutMS=0`;
39
- }
31
+ // For SRV, use only the first host
32
+ connectUrl += this.conf.hosts[0].host;
33
+ // Append the database name
34
+ connectUrl += `/${dbName}?retryWrites=true&w=majority`;
40
35
  // Mask sensitive information in logs
41
36
  const safeConnectUrl = connectUrl.replace(/\/\/.*?:.*?@/, "//*****:*****@");
42
37
  debug(`Connecting to MongoDB: ${safeConnectUrl}`);
43
- // Define connection options with timeouts
44
38
  const options = {
45
39
  connectTimeoutMS: 2000, // 2 seconds
46
40
  serverSelectionTimeoutMS: 2000, // 2 seconds
47
- // Additional options can be added here
41
+ // TLS/SSL is handled automatically with mongodb+srv
48
42
  };
49
43
  try {
50
44
  // Establish MongoDB connection
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frogfish/k2db",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "A data handling library for K2 applications.",
5
5
  "main": "data.js",
6
6
  "types": "data.d.ts",