Skip to content

Commit 74cfadf

Browse files
committed
Identify powersync in MongoDB connections.
1 parent e8cb8db commit 74cfadf

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

libs/lib-mongodb/src/db/mongo.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as mongo from 'mongodb';
22
import * as timers from 'timers/promises';
33
import { BaseMongoConfigDecoded, normalizeMongoConfig } from '../types/types.js';
4-
import { validateIpHostname } from '@powersync/lib-services-framework';
54

65
/**
76
* Time for new connection to timeout.
@@ -33,6 +32,9 @@ export interface MongoConnectionOptions {
3332
maxPoolSize: number;
3433
}
3534

35+
/**
36+
* Create a MongoClient for the storage database.
37+
*/
3638
export function createMongoClient(config: BaseMongoConfigDecoded, options?: MongoConnectionOptions) {
3739
const normalized = normalizeMongoConfig(config);
3840
return new mongo.MongoClient(normalized.uri, {
@@ -47,6 +49,9 @@ export function createMongoClient(config: BaseMongoConfigDecoded, options?: Mong
4749
// How long to wait for new primary selection
4850
serverSelectionTimeoutMS: 30_000,
4951

52+
// Identify the client
53+
appName: 'powersync-storage',
54+
5055
lookup: normalized.lookup,
5156

5257
// Avoid too many connections:

modules/module-mongodb-storage/src/storage/implementation/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function replicaIdToSubkey(table: bson.ObjectId, id: storage.ReplicaId):
107107
/**
108108
* Helper function for creating a MongoDB client from consumers of this package
109109
*/
110-
export const createMongoClient = (url: string, options?: mongo.MongoClientOptions) => {
110+
const createMongoClient = (url: string, options?: mongo.MongoClientOptions) => {
111111
return new mongo.MongoClient(url, options);
112112
};
113113

modules/module-mongodb/src/replication/MongoManager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { mongo } from '@powersync/lib-service-mongodb';
33
import { NormalizedMongoConnectionConfig } from '../types/types.js';
44
import { BSON_DESERIALIZE_DATA_OPTIONS } from '@powersync/service-core';
55

6+
/**
7+
* Manage a MongoDB source database connection.
8+
*/
69
export class MongoManager {
710
public readonly client: mongo.MongoClient;
811
public readonly db: mongo.Db;
@@ -26,6 +29,9 @@ export class MongoManager {
2629
// How long to wait for new primary selection
2730
serverSelectionTimeoutMS: 30_000,
2831

32+
// Identify the client
33+
appName: 'powersync',
34+
2935
// Avoid too many connections:
3036
// 1. It can overwhelm the source database.
3137
// 2. Processing too many queries in parallel can cause the process to run out of memory.

0 commit comments

Comments
 (0)