Skip to content

Commit

Permalink
backported
Browse files Browse the repository at this point in the history
  • Loading branch information
IslandRhythms committed Jul 20, 2023
1 parent 20b030e commit 1b09cb1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/drivers/node-mongodb-native/collection.js
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
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

0 comments on commit 1b09cb1

Please sign in to comment.