Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
allow mongoose.connection.db to be undefined
  • Loading branch information
IslandRhythms committed Aug 8, 2024
commit 3c955b1d3518e8f9612667b01a71e06e5b758e4a
1 change: 1 addition & 0 deletions test/types/connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ import { expectType } from 'tsd';
expectType<Promise<typeof mongoose>>(connect('mongodb://127.0.0.1:27017/test'));
expectType<Promise<typeof mongoose>>(connect('mongodb://127.0.0.1:27017/test', {}));
expectType<Promise<typeof mongoose>>(connect('mongodb://127.0.0.1:27017/test', { bufferCommands: true }));
expectType<Promise<typeof mongoose>>(connect('mongodb://127.0.0.1:27017/test', { bufferCommands: true }));
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