Skip to content

Commit

Permalink
Merge pull request #14797 from Automattic/IslandRhythms/gh-14789
Browse files Browse the repository at this point in the history
allow `mongoose.connection.db` to be undefined
  • Loading branch information
vkarpov15 authored Aug 8, 2024
2 parents f356452 + 7d5c845 commit 5d6463b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions test/types/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ expectType<Array<string>>(conn.modelNames());
expectType<Promise<void>>(createConnection('mongodb://127.0.0.1:27017/test').close());
expectType<Promise<void>>(createConnection('mongodb://127.0.0.1:27017/test').close(true));

expectType<mongodb.Db>(conn.db);
expectType<mongodb.Db | undefined>(conn.db);

expectType<mongodb.MongoClient>(conn.getClient());
expectType<Connection>(conn.setClient(new mongodb.MongoClient('mongodb://127.0.0.1:27017/test')));
Expand All @@ -65,7 +65,7 @@ expectError(conn.host = 'invalid');
expectError(conn.port = 'invalid');

expectType<Collection>(conn.collection('test'));
expectType<mongodb.Collection>(conn.db.collection('test'));
expectType<mongodb.Collection | undefined>(conn.db?.collection('test'));

expectType<Promise<mongodb.ClientSession>>(conn.startSession());
expectType<Promise<mongodb.ClientSession>>(conn.startSession({ causalConsistency: true }));
Expand Down
2 changes: 1 addition & 1 deletion types/connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ declare module 'mongoose' {
readonly config: any;

/** The mongodb.Db instance, set when the connection is opened */
readonly db: mongodb.Db;
readonly db: mongodb.Db | undefined;

/**
* Helper for `createCollection()`. Will explicitly create the given collection
Expand Down

0 comments on commit 5d6463b

Please sign in to comment.