Skip to content

Commit 848e34f

Browse files
authored
Merge branch 'vkarpov15/mquery-v6' into vkarpov15/remove-old-methods
2 parents 4716c31 + d22970e commit 848e34f

File tree

3 files changed

+28
-54
lines changed

3 files changed

+28
-54
lines changed

lib/mquery.js

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
const assert = require('assert');
88
const util = require('util');
99
const utils = require('./utils');
10-
const debug = require('debug')('mquery');
1110

1211
/**
1312
* Query constructor used for building queries.
@@ -1857,8 +1856,6 @@ Query.prototype._find = async function _find() {
18571856
options.fields = this._fieldsForExec();
18581857
}
18591858

1860-
debug('_find', this._collection.collectionName, conds, options);
1861-
18621859
return this._collection.find(conds, options);
18631860
};
18641861

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

1896-
debug('findCursor', this._collection.collectionName, conds, options);
18971893
return this._collection.findCursor(conds, options);
18981894
};
18991895

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

1940-
debug('findOne', this._collection.collectionName, conds, options);
1941-
19421936
return this._collection.findOne(conds, options);
19431937
};
19441938

@@ -2011,11 +2005,8 @@ Query.prototype.estimatedDocumentCount = function() {
20112005
* @returns the results
20122006
*/
20132007
Query.prototype._estimatedDocumentCount = async function _estimatedDocumentCount() {
2014-
const conds = this._conditions,
2015-
options = this._optionsForExec();
2016-
2017-
debug('estimatedDocumentCount', this._collection.collectionName, conds, options);
2018-
2008+
const conds = this._conditions;
2009+
const options = this._optionsForExec();
20192010
return this._collection.estimatedDocumentCount(conds, options);
20202011
};
20212012

@@ -2070,8 +2061,6 @@ Query.prototype._distinct = async function _distinct() {
20702061
const conds = this._conditions,
20712062
options = this._optionsForExec();
20722063

2073-
debug('distinct', this._collection.collectionName, conds, options);
2074-
20752064
return this._collection.distinct(this._distinctDoc, conds, options);
20762065
};
20772066

@@ -2216,8 +2205,6 @@ async function _updateExec(query, op) {
22162205
const criteria = query._conditions;
22172206
const doc = query._updateForExec();
22182207

2219-
debug('update', query._collection.collectionName, criteria, doc, options);
2220-
22212208
return query._collection[op](criteria, doc, options);
22222209
}
22232210

@@ -2253,8 +2240,6 @@ Query.prototype._deleteOne = async function() {
22532240

22542241
const conds = this._conditions;
22552242

2256-
debug('deleteOne', this._collection.collectionName, conds, options);
2257-
22582243
return this._collection.deleteOne(conds, options);
22592244
};
22602245

@@ -2291,8 +2276,6 @@ Query.prototype._deleteMany = async function() {
22912276

22922277
const conds = this._conditions;
22932278

2294-
debug('deleteOne', this._collection.collectionName, conds, options);
2295-
22962279
return this._collection.deleteMany(conds, options);
22972280
};
22982281

@@ -2499,8 +2482,6 @@ Query.prototype.cursor = function() {
24992482
options.fields = this._fieldsForExec();
25002483
}
25012484

2502-
debug('cursor', this._collection.collectionName, conds, options);
2503-
25042485
return this._collection.findCursor(conds, options);
25052486
};
25062487

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@
1515
"engines": {
1616
"node": ">=16.0.0"
1717
},
18-
"dependencies": {
19-
"debug": "4.x"
20-
},
2118
"devDependencies": {
2219
"eslint": "8.x",
2320
"eslint-plugin-mocha-no-only": "1.1.1",
24-
"mocha": "9.x",
21+
"mocha": "11.x",
2522
"mongodb": "6.x"
2623
},
2724
"bugs": {

test/index.js

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ describe('mquery', function() {
20142014
await col.insertOne({ name: name });
20152015
const m = mquery({ name: name }).collection(col);
20162016
name = '1 arg';
2017-
const n = m.updateOne({ $set: { name: name } }).setOptions({ returnDocument: 'after' });
2017+
const n = m.updateOne({ $set: { name: name } }).setOptions({ returnDocument: 'after', includeResultMetadata: true });
20182018
const res = await n.findOneAndUpdate();
20192019
assert.ok(res);
20202020
assert.equal(res.name, name);
@@ -2036,8 +2036,8 @@ describe('mquery', function() {
20362036
});
20372037
it('update + exec', async() => {
20382038
const m = mquery().collection(col).where({ name: name });
2039-
const res = await m.findOneAndUpdate({}, { $inc: { age: 10 } }, { returnDocument: 'after' });
2040-
assert.equal(res.age, 10);
2039+
const res = await m.findOneAndUpdate({}, { $inc: { age: 10 } }, { returnDocument: 'after', includeResultMetadata: true });
2040+
assert.equal(10, res.value.age);
20412041
});
20422042
});
20432043
describe('with 3 args', function() {
@@ -2050,19 +2050,17 @@ describe('mquery', function() {
20502050
});
20512051
it('conditions + update + exec', async() => {
20522052
const m = mquery().collection(col);
2053-
const res = await m.findOneAndUpdate({ name: name }, { works: true }, { returnDocument: 'after' });
2054-
assert.ok(res);
2055-
assert.equal(res.name, name);
2056-
assert.ok(res.works);
2053+
const res = await m.findOneAndUpdate({ name: name }, { works: true }, { returnDocument: 'after', includeResultMetadata: true });
2054+
assert.ok(res.value);
2055+
assert.equal(name, res.value.name);
2056+
assert.ok(true === res.value.works);
20572057
});
2058-
});
2059-
describe('with 4 args', function() {
2060-
it('conditions + update + options + exec', async() => {
2058+
it('empty options', async() => {
20612059
const m = mquery().collection(col);
20622060
const res = await m.findOneAndUpdate({ name: name }, { works: false }, {});
20632061
assert.ok(res);
2064-
assert.equal(res.name, name);
2065-
assert.ok(res.works);
2062+
assert.equal(name, res.name);
2063+
assert.ok(true === res.works);
20662064
});
20672065
});
20682066
});
@@ -2094,12 +2092,12 @@ describe('mquery', function() {
20942092
assert.deepEqual(n._conditions, { name: name });
20952093
});
20962094
});
2097-
it('that is a function', async() => {
2095+
it('executes', async() => {
20982096
await col.insertOne({ name: name });
20992097
const m = mquery({ name: name }).collection(col);
2100-
const res = await m.findOneAndDelete();
2098+
const res = await m.findOneAndRemove();
21012099
assert.ok(res);
2102-
assert.equal(res.name, name);
2100+
assert.equal(name, res.name);
21032101
});
21042102
});
21052103
describe('with 2 args', function() {
@@ -2119,25 +2117,23 @@ describe('mquery', function() {
21192117
it('conditions + exec', async() => {
21202118
await col.insertOne({ name: name });
21212119
const m = mquery().collection(col);
2122-
const res = await m.findOneAndDelete({ name: name });
2123-
assert.equal(res.name, name);
2120+
const res = await m.findOneAndRemove({ name: name });
2121+
assert.equal(name, res.name);
21242122
});
21252123
it('query + exec', async() => {
21262124
await col.insertOne({ name: name });
21272125
const n = mquery({ name: name });
21282126
const m = mquery().collection(col);
2129-
const res = await m.findOneAndDelete(n);
2130-
assert.equal(res.name, name);
2127+
const res = await m.findOneAndRemove(n);
2128+
assert.equal(name, res.name);
21312129
});
2132-
});
2133-
describe('with 3 args', function() {
21342130
it('conditions + options + exec', async() => {
21352131
name = 'findOneAndDelete + conds + options + cb';
21362132
await col.insertMany([{ name: name }, { name: 'a' }]);
21372133
const m = mquery().collection(col);
2138-
const res = await m.findOneAndDelete({ name: name }, { sort: { name: 1 } });
2139-
assert.ok(res);
2140-
assert.equal(res.name, name);
2134+
const res = await m.findOneAndRemove({ name: name }, { sort: { name: 1 }, includeResultMetadata: true });
2135+
assert.ok(res.value);
2136+
assert.equal(name, res.value.name);
21412137
});
21422138
});
21432139
});
@@ -2291,7 +2287,7 @@ describe('mquery', function() {
22912287
describe('findOneAndUpdate', function() {
22922288
it('with exec', async() => {
22932289
const m = mquery().collection(col);
2294-
m.findOneAndUpdate({ name: 'exec', age: 1 }, { $set: { name: 'findOneAndUpdate' } }, { returnDocument: 'after' });
2290+
m.findOneAndUpdate({ name: 'exec', age: 1 }, { $set: { name: 'findOneAndUpdate' } }, { returnDocument: 'after', includeResultMetadata: true });
22952291
const res = await m.exec();
22962292
assert.equal(res.name, 'findOneAndUpdate');
22972293
});
@@ -2302,10 +2298,10 @@ describe('mquery', function() {
23022298
const m = mquery().collection(col);
23032299
m.findOneAndDelete({ name: 'exec', age: 2 });
23042300
const res = await m.exec();
2305-
assert.equal(res.name, 'exec');
2306-
assert.equal(res.age, 2);
2307-
const num = await mquery().collection(col).countDocuments({ name: 'exec' });
2308-
assert.equal(num, 1);
2301+
assert.equal('exec', res.name);
2302+
assert.equal(2, res.age);
2303+
const num = await mquery().collection(col).count({ name: 'exec' });
2304+
assert.equal(1, num);
23092305
});
23102306
});
23112307
});

0 commit comments

Comments
 (0)