Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion lib/types/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class MongooseMap extends Map {
v.$__.wasPopulated = { value: v._id };
return v;
});
} else {
} else if (value != null) {
if (value.$__ == null) {
value = new populated.options[populateModelSymbol](value);
}
Expand Down
5 changes: 4 additions & 1 deletion test/docs/transactions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ describe('transactions', function() {
const doc = await Test.findById(_id).orFail();
let attempt = 0;

await db.transaction(async(session) => {
const res = await db.transaction(async(session) => {
await doc.save({ session });

if (attempt === 0) {
Expand All @@ -489,7 +489,10 @@ describe('transactions', function() {
errorLabels: [mongoose.mongo.MongoErrorLabel.TransientTransactionError]
});
}

return { answer: 42 };
});
assert.deepStrictEqual(res, { answer: 42 });

const { items } = await Test.findById(_id).orFail();
assert.ok(Array.isArray(items));
Expand Down
6 changes: 3 additions & 3 deletions test/types/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ expectType<mongodb.Db>(conn.db);
expectType<mongodb.MongoClient>(conn.getClient());
expectType<Connection>(conn.setClient(new mongodb.MongoClient('mongodb://127.0.0.1:27017/test')));

expectType<Promise<void>>(conn.transaction(async(res) => {
expectType<Promise<string>>(conn.transaction(async(res) => {
expectType<mongodb.ClientSession>(res);
return 'a';
}));
expectType<Promise<void>>(conn.transaction(async(res) => {
expectType<Promise<string>>(conn.transaction(async(res) => {
expectType<mongodb.ClientSession>(res);
return 'a';
}, { readConcern: 'majority' }));
Expand Down Expand Up @@ -148,4 +148,4 @@ function schemaInstanceMethodsAndQueryHelpersOnConnection() {
});

const TestModel = connection.model<User, UserModel, UserQueryHelpers>('User', userSchema);
}
}
2 changes: 1 addition & 1 deletion types/connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ declare module 'mongoose' {
* async function executes successfully and attempt to retry if
* there was a retryable error.
*/
transaction(fn: (session: mongodb.ClientSession) => Promise<any>, options?: mongodb.TransactionOptions): Promise<void>;
transaction<ReturnType = unknown>(fn: (session: mongodb.ClientSession) => Promise<ReturnType>, options?: mongodb.TransactionOptions): Promise<ReturnType>;

/** Switches to a different database using the same connection pool. */
useDb(name: string, options?: { useCache?: boolean, noListener?: boolean }): Connection;
Expand Down