Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backported gh-13364 #13637

Merged
merged 1 commit into from
Jul 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/drivers/node-mongodb-native/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,14 @@ function iter(i) {

if (debug) {
if (typeof debug === 'function') {
let argsToAdd = null;
if (typeof args[args.length - 1] == 'function') {
argsToAdd = args.slice(0, args.length - 1);
} else {
argsToAdd = args;
}
debug.apply(_this,
[_this.name, i].concat(args.slice(0, args.length - 1)));
[_this.name, i].concat(argsToAdd));
} else if (debug instanceof stream.Writable) {
this.$printToStream(_this.name, i, args, debug);
} else {
Expand Down
13 changes: 13 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ describe('mongoose module:', function() {
await mongoose.disconnect();
});

it('should collect the args correctly gh-13364', async function() {
const util = require('util');
const mongoose = new Mongoose();
const conn = await mongoose.connect(start.uri);
let actual = '';
mongoose.set('debug', (collectionName, methodName, ...methodArgs) => {
actual = `${collectionName}.${methodName}(${util.inspect(methodArgs).slice(2, -2)})`;
});
const user = conn.connection.collection('User');
await user.findOne({ key: 'value' });
assert.equal('User.findOne({ key: \'value\' })', actual);
});

it('{g,s}etting options', function() {
const mongoose = new Mongoose();

Expand Down