Skip to content

Commit 0ec03bf

Browse files
chore(NODE-4177): remove unused Server.query method (#3196)
1 parent 4091c9a commit 0ec03bf

File tree

3 files changed

+2
-185
lines changed

3 files changed

+2
-185
lines changed

src/cmap/connection.ts

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
} from '../error';
2222
import type { ServerApi, SupportedNodeConnectionOptions } from '../mongo_client';
2323
import { CancellationToken, TypedEventEmitter } from '../mongo_types';
24-
import { ReadPreference, ReadPreferenceLike } from '../read_preference';
24+
import type { ReadPreference, ReadPreferenceLike } from '../read_preference';
2525
import { applySession, ClientSession, updateSessionFromResponse } from '../sessions';
2626
import {
2727
calculateDurationInMs,
@@ -45,7 +45,6 @@ import {
4545
GetMore,
4646
KillCursor,
4747
Msg,
48-
OpQueryOptions,
4948
Query,
5049
Response,
5150
WriteProtocolMessageType
@@ -565,78 +564,6 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
565564
}
566565
}
567566

568-
query(ns: MongoDBNamespace, cmd: Document, options: QueryOptions, callback: Callback): void {
569-
const isExplain = cmd.$explain != null;
570-
const readPreference = options.readPreference ?? ReadPreference.primary;
571-
const batchSize = options.batchSize || 0;
572-
const limit = options.limit;
573-
const numberToSkip = options.skip || 0;
574-
let numberToReturn = 0;
575-
if (
576-
limit &&
577-
(limit < 0 || (limit !== 0 && limit < batchSize) || (limit > 0 && batchSize === 0))
578-
) {
579-
numberToReturn = limit;
580-
} else {
581-
numberToReturn = batchSize;
582-
}
583-
584-
if (isExplain) {
585-
// nToReturn must be 0 (match all) or negative (match N and close cursor)
586-
// nToReturn > 0 will give explain results equivalent to limit(0)
587-
numberToReturn = -Math.abs(limit || 0);
588-
}
589-
590-
const queryOptions: OpQueryOptions = {
591-
numberToSkip,
592-
numberToReturn,
593-
pre32Limit: typeof limit === 'number' ? limit : undefined,
594-
checkKeys: false,
595-
secondaryOk: readPreference.secondaryOk()
596-
};
597-
598-
if (options.projection) {
599-
queryOptions.returnFieldSelector = options.projection;
600-
}
601-
602-
const query = new Query(ns.toString(), cmd, queryOptions);
603-
if (typeof options.tailable === 'boolean') {
604-
query.tailable = options.tailable;
605-
}
606-
607-
if (typeof options.oplogReplay === 'boolean') {
608-
query.oplogReplay = options.oplogReplay;
609-
}
610-
611-
if (typeof options.timeout === 'boolean') {
612-
query.noCursorTimeout = !options.timeout;
613-
} else if (typeof options.noCursorTimeout === 'boolean') {
614-
query.noCursorTimeout = options.noCursorTimeout;
615-
}
616-
617-
if (typeof options.awaitData === 'boolean') {
618-
query.awaitData = options.awaitData;
619-
}
620-
621-
if (typeof options.partial === 'boolean') {
622-
query.partial = options.partial;
623-
}
624-
625-
write(
626-
this,
627-
query,
628-
{ [kFullResult]: true, ...pluckBSONSerializeOptions(options) },
629-
(err, result) => {
630-
if (err || !result) return callback(err, result);
631-
if (isExplain && result.documents && result.documents[0]) {
632-
return callback(undefined, result.documents[0]);
633-
}
634-
635-
callback(undefined, result);
636-
}
637-
);
638-
}
639-
640567
getMore(
641568
ns: MongoDBNamespace,
642569
cursorId: Long,

src/operations/find.ts

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Document } from '../bson';
2-
import { isSharded } from '../cmap/wire_protocol/shared';
32
import type { Collection } from '../collection';
43
import { MongoCompatibilityError, MongoInvalidArgumentError } from '../error';
54
import { ReadConcern } from '../read_concern';
@@ -128,37 +127,6 @@ export class FindOperation extends CommandOperation<Document> {
128127
return;
129128
}
130129

131-
if (serverWireVersion < 4) {
132-
if (this.readConcern && this.readConcern.level !== 'local') {
133-
callback(
134-
new MongoCompatibilityError(
135-
`Server find command does not support a readConcern level of ${this.readConcern.level}`
136-
)
137-
);
138-
139-
return;
140-
}
141-
142-
const findCommand = makeLegacyFindCommand(this.ns, this.filter, options);
143-
if (isSharded(server) && this.readPreference) {
144-
findCommand.$readPreference = this.readPreference.toJSON();
145-
}
146-
147-
server.query(
148-
this.ns,
149-
findCommand,
150-
{
151-
...this.options,
152-
...this.bsonOptions,
153-
documentsReturnedIn: 'firstBatch',
154-
readPreference: this.readPreference
155-
},
156-
callback
157-
);
158-
159-
return;
160-
}
161-
162130
let findCommand = makeFindCommand(this.ns, this.filter, options);
163131
if (this.explain) {
164132
findCommand = decorateWithExplain(findCommand, this.explain);
@@ -303,54 +271,6 @@ function makeFindCommand(ns: MongoDBNamespace, filter: Document, options: FindOp
303271
return findCommand;
304272
}
305273

306-
function makeLegacyFindCommand(
307-
ns: MongoDBNamespace,
308-
filter: Document,
309-
options: FindOptions
310-
): Document {
311-
const findCommand: Document = {
312-
$query: filter
313-
};
314-
315-
if (options.sort) {
316-
findCommand.$orderby = formatSort(options.sort);
317-
}
318-
319-
if (options.hint) {
320-
findCommand.$hint = normalizeHintField(options.hint);
321-
}
322-
323-
if (typeof options.returnKey === 'boolean') {
324-
findCommand.$returnKey = options.returnKey;
325-
}
326-
327-
if (options.max) {
328-
findCommand.$max = options.max;
329-
}
330-
331-
if (options.min) {
332-
findCommand.$min = options.min;
333-
}
334-
335-
if (typeof options.showRecordId === 'boolean') {
336-
findCommand.$showDiskLoc = options.showRecordId;
337-
}
338-
339-
if (options.comment) {
340-
findCommand.$comment = options.comment;
341-
}
342-
343-
if (typeof options.maxTimeMS === 'number') {
344-
findCommand.$maxTimeMS = options.maxTimeMS;
345-
}
346-
347-
if (options.explain != null) {
348-
findCommand.$explain = true;
349-
}
350-
351-
return findCommand;
352-
}
353-
354274
defineAspects(FindOperation, [
355275
Aspect.READ_OPERATION,
356276
Aspect.RETRYABLE,

src/sdam/server.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import type { Document, Long } from '../bson';
2-
import {
3-
CommandOptions,
4-
Connection,
5-
DestroyOptions,
6-
GetMoreOptions,
7-
QueryOptions
8-
} from '../cmap/connection';
2+
import { CommandOptions, Connection, DestroyOptions, GetMoreOptions } from '../cmap/connection';
93
import {
104
ConnectionPool,
115
ConnectionPoolEvents,
@@ -364,30 +358,6 @@ export class Server extends TypedEventEmitter<ServerEvents> {
364358
);
365359
}
366360

367-
/**
368-
* Execute a query against the server
369-
* @internal
370-
*/
371-
query(ns: MongoDBNamespace, cmd: Document, options: QueryOptions, callback: Callback): void {
372-
if (this.s.state === STATE_CLOSING || this.s.state === STATE_CLOSED) {
373-
callback(new MongoServerClosedError());
374-
return;
375-
}
376-
377-
this.s.pool.withConnection(
378-
undefined,
379-
(err, conn, cb) => {
380-
if (err || !conn) {
381-
markServerUnknown(this, err);
382-
return cb(err);
383-
}
384-
385-
conn.query(ns, cmd, options, makeOperationHandler(this, conn, cmd, options, cb));
386-
},
387-
callback
388-
);
389-
}
390-
391361
/**
392362
* Execute a `getMore` against the server
393363
* @internal

0 commit comments

Comments
 (0)