Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/federation-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ export async function init({
emitter?: Emitter<HomeserverEventSignatures>;
dbConfig: {
uri: string;
name: string;
poolSize: number;
};
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ export class DatabaseConnectionService {
private connectionPromise: Promise<void> | null = null;
private readonly logger = createLogger('DatabaseConnectionService');

constructor(
private readonly config: { uri: string; name: string; poolSize: number },
) {
constructor(private readonly config: { uri: string; poolSize: number }) {
this.connect().catch((err) =>
this.logger.error({ msg: 'Initial database connection failed', err }),
);
Expand Down Expand Up @@ -47,8 +45,15 @@ export class DatabaseConnectionService {
this.client = new MongoClient(dbConfig.uri, options);
this.client.connect();

this.db = this.client.db(dbConfig.name);
this.logger.info(`Connected to MongoDB database: ${dbConfig.name}`);
const dbName = this.client.options.dbName;
if (!dbName) {
throw new Error(
"Can't get database name from MongoDB connection string",
);
}

this.db = this.client.db(dbName);
this.logger.info(`Connected to MongoDB database: ${dbName}`);

resolve();
} catch (error: unknown) {
Expand Down
3 changes: 1 addition & 2 deletions packages/homeserver/src/homeserver.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ export async function setup() {

await init({
dbConfig: {
uri: process.env.MONGODB_URI || 'mongodb://localhost:27017/matrix',
name: process.env.DATABASE_NAME || 'matrix',
uri: process.env.MONGO_URL || 'mongodb://localhost:27017/matrix',
poolSize: Number.parseInt(process.env.DATABASE_POOL_SIZE || '10', 10),
},
});
Expand Down