Skip to content
Open

v6 #141

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
18 changes: 0 additions & 18 deletions lib/mquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
const assert = require('assert');
const util = require('util');
const utils = require('./utils');
const debug = require('debug')('mquery');

/**
* Query constructor used for building queries.
Expand Down Expand Up @@ -1857,8 +1856,6 @@ Query.prototype._find = async function _find() {
options.fields = this._fieldsForExec();
}

debug('_find', this._collection.collectionName, conds, options);

return this._collection.find(conds, options);
};

Expand Down Expand Up @@ -1893,7 +1890,6 @@ Query.prototype.cursor = function cursor(criteria) {
options.fields = this._fieldsForExec();
}

debug('findCursor', this._collection.collectionName, conds, options);
return this._collection.findCursor(conds, options);
};

Expand Down Expand Up @@ -1937,8 +1933,6 @@ Query.prototype._findOne = async function _findOne() {
options.fields = this._fieldsForExec();
}

debug('findOne', this._collection.collectionName, conds, options);

return this._collection.findOne(conds, options);
};

Expand Down Expand Up @@ -1981,8 +1975,6 @@ Query.prototype._count = async function _count() {
const conds = this._conditions,
options = this._optionsForExec();

debug('count', this._collection.collectionName, conds, options);

return this._collection.count(conds, options);
};

Expand Down Expand Up @@ -2037,8 +2029,6 @@ Query.prototype._distinct = async function _distinct() {
const conds = this._conditions,
options = this._optionsForExec();

debug('distinct', this._collection.collectionName, conds, options);

return this._collection.distinct(this._distinctDoc, conds, options);
};

Expand Down Expand Up @@ -2183,8 +2173,6 @@ async function _updateExec(query, op) {
const criteria = query._conditions;
const doc = query._updateForExec();

debug('update', query._collection.collectionName, criteria, doc, options);

return query._collection[op](criteria, doc, options);
}

Expand Down Expand Up @@ -2220,8 +2208,6 @@ Query.prototype._deleteOne = async function() {

const conds = this._conditions;

debug('deleteOne', this._collection.collectionName, conds, options);

return this._collection.deleteOne(conds, options);
};

Expand Down Expand Up @@ -2258,8 +2244,6 @@ Query.prototype._deleteMany = async function() {

const conds = this._conditions;

debug('deleteOne', this._collection.collectionName, conds, options);

return this._collection.deleteMany(conds, options);
};

Expand Down Expand Up @@ -2469,8 +2453,6 @@ Query.prototype.cursor = function() {
options.fields = this._fieldsForExec();
}

debug('cursor', this._collection.collectionName, conds, options);

return this._collection.findCursor(conds, options);
};

Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
"engines": {
"node": ">=14.0.0"
},
"dependencies": {
"debug": "4.x"
},
"devDependencies": {
"eslint": "8.x",
"eslint-plugin-mocha-no-only": "1.1.1",
"mocha": "9.x",
"mongodb": "5.x"
"mocha": "11.x",
"mongodb": "6.x"
},
"bugs": {
"url": "https://github.com/aheckmann/mquery/issues/new"
Expand Down
36 changes: 16 additions & 20 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ describe('mquery', function() {
await col.insertOne({ name: name });
const m = mquery({ name: name }).collection(col);
name = '1 arg';
const n = m.updateOne({ $set: { name: name } }).setOptions({ returnDocument: 'after' });
const n = m.updateOne({ $set: { name: name } }).setOptions({ returnDocument: 'after', includeResultMetadata: true });
const res = await n.findOneAndUpdate();
assert.ok(res.value);
assert.equal(res.value.name, name);
Expand All @@ -2036,7 +2036,7 @@ describe('mquery', function() {
});
it('update + exec', async() => {
const m = mquery().collection(col).where({ name: name });
const res = await m.findOneAndUpdate({}, { $inc: { age: 10 } }, { returnDocument: 'after' });
const res = await m.findOneAndUpdate({}, { $inc: { age: 10 } }, { returnDocument: 'after', includeResultMetadata: true });
assert.equal(10, res.value.age);
});
});
Expand All @@ -2050,19 +2050,17 @@ describe('mquery', function() {
});
it('conditions + update + exec', async() => {
const m = mquery().collection(col);
const res = await m.findOneAndUpdate({ name: name }, { works: true }, { returnDocument: 'after' });
const res = await m.findOneAndUpdate({ name: name }, { works: true }, { returnDocument: 'after', includeResultMetadata: true });
assert.ok(res.value);
assert.equal(name, res.value.name);
assert.ok(true === res.value.works);
});
});
describe('with 4 args', function() {
it('conditions + update + options + exec', async() => {
it('empty options', async() => {
const m = mquery().collection(col);
const res = await m.findOneAndUpdate({ name: name }, { works: false }, {});
assert.ok(res.value);
assert.equal(name, res.value.name);
assert.ok(true === res.value.works);
assert.ok(res);
assert.equal(name, res.name);
assert.ok(true === res.works);
});
});
});
Expand Down Expand Up @@ -2094,12 +2092,12 @@ describe('mquery', function() {
assert.deepEqual(n._conditions, { name: name });
});
});
it('that is a function', async() => {
it('executes', async() => {
await col.insertOne({ name: name });
const m = mquery({ name: name }).collection(col);
const res = await m.findOneAndRemove();
assert.ok(res.value);
assert.equal(name, res.value.name);
assert.ok(res);
assert.equal(name, res.name);
});
});
describe('with 2 args', function() {
Expand All @@ -2120,22 +2118,20 @@ describe('mquery', function() {
await col.insertOne({ name: name });
const m = mquery().collection(col);
const res = await m.findOneAndRemove({ name: name });
assert.equal(name, res.value.name);
assert.equal(name, res.name);
});
it('query + exec', async() => {
await col.insertOne({ name: name });
const n = mquery({ name: name });
const m = mquery().collection(col);
const res = await m.findOneAndRemove(n);
assert.equal(name, res.value.name);
assert.equal(name, res.name);
});
});
describe('with 3 args', function() {
it('conditions + options + exec', async() => {
name = 'findOneAndRemove + conds + options + cb';
await col.insertMany([{ name: name }, { name: 'a' }]);
const m = mquery().collection(col);
const res = await m.findOneAndRemove({ name: name }, { sort: { name: 1 } });
const res = await m.findOneAndRemove({ name: name }, { sort: { name: 1 }, includeResultMetadata: true });
assert.ok(res.value);
assert.equal(name, res.value.name);
});
Expand Down Expand Up @@ -2291,7 +2287,7 @@ describe('mquery', function() {
describe('findOneAndUpdate', function() {
it('with exec', async() => {
const m = mquery().collection(col);
m.findOneAndUpdate({ name: 'exec', age: 1 }, { $set: { name: 'findOneAndUpdate' } }, { returnDocument: 'after' });
m.findOneAndUpdate({ name: 'exec', age: 1 }, { $set: { name: 'findOneAndUpdate' } }, { returnDocument: 'after', includeResultMetadata: true });
const res = await m.exec();
assert.equal('findOneAndUpdate', res.value.name);
});
Expand All @@ -2302,8 +2298,8 @@ describe('mquery', function() {
const m = mquery().collection(col);
m.findOneAndRemove({ name: 'exec', age: 2 });
const res = await m.exec();
assert.equal('exec', res.value.name);
assert.equal(2, res.value.age);
assert.equal('exec', res.name);
assert.equal(2, res.age);
const num = await mquery().collection(col).count({ name: 'exec' });
assert.equal(1, num);
});
Expand Down
Loading