Skip to content

Commit 0e6375a

Browse files
author
Thomas Reggi
authored
refactor!: remove deprecated find options
NODE-2816
1 parent 054838f commit 0e6375a

11 files changed

+44
-227
lines changed

src/cursor/cursor.ts

-41
Original file line numberDiff line numberDiff line change
@@ -329,21 +329,6 @@ export class Cursor<
329329
return this;
330330
}
331331

332-
/**
333-
* Set the cursor maxScan
334-
*
335-
* @deprecated Instead, use maxTimeMS option or the helper {@link Cursor.maxTimeMS}.
336-
* @param maxScan - Constrains the query to only scan the specified number of documents when fulfilling the query
337-
*/
338-
maxScan(maxScan: number): this {
339-
if (this.s.state === CursorState.CLOSED || this.s.state === CursorState.OPEN || this.isDead()) {
340-
throw new MongoError('Cursor is closed');
341-
}
342-
343-
this.cmd.maxScan = maxScan;
344-
return this;
345-
}
346-
347332
/**
348333
* Set the cursor hint
349334
*
@@ -416,27 +401,10 @@ export class Cursor<
416401
return this;
417402
}
418403

419-
/**
420-
* Set the cursor snapshot
421-
*
422-
* @deprecated as of MongoDB 4.0
423-
*
424-
* @param value - The $snapshot operator prevents the cursor from returning a document more than once because an intervening write operation results in a move of the document.
425-
*/
426-
snapshot(value: boolean): this {
427-
if (this.s.state === CursorState.CLOSED || this.s.state === CursorState.OPEN || this.isDead()) {
428-
throw new MongoError('Cursor is closed');
429-
}
430-
431-
this.cmd.snapshot = value;
432-
return this;
433-
}
434-
435404
/**
436405
* Set a node.js specific cursor option
437406
*
438407
* @param field - The cursor option to set 'numberOfRetries' | 'tailableRetryInterval'.
439-
*
440408
* @param value - The field value.
441409
*/
442410
setCursorOption(field: typeof FIELDS[number], value: number): this {
@@ -977,12 +945,3 @@ export class Cursor<
977945

978946
// deprecated methods
979947
deprecate(Cursor.prototype.each, 'Cursor.each is deprecated. Use Cursor.forEach instead.');
980-
deprecate(
981-
Cursor.prototype.maxScan,
982-
'Cursor.maxScan is deprecated, and will be removed in a later version'
983-
);
984-
985-
deprecate(
986-
Cursor.prototype.snapshot,
987-
'Cursor Snapshot is deprecated, and will be removed in a later version'
988-
);

src/gridfs-stream/upload.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ function checkDone(stream: GridFSBucketWriteStream, callback?: Callback): boolea
334334
}
335335

336336
function checkIndexes(stream: GridFSBucketWriteStream, callback: Callback): void {
337-
stream.files.findOne({}, { fields: { _id: 1 } }, (error, doc) => {
337+
stream.files.findOne({}, { projection: { _id: 1 } }, (error, doc) => {
338338
if (error) {
339339
return callback(error);
340340
}

src/operations/find.ts

+2-33
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,6 @@ export interface FindOptions extends QueryOptions, CommandOperationOptions {
6969
allowPartialResults?: boolean;
7070
/** Determines whether to return the record identifier for each document. If true, adds a field $recordId to the returned documents. */
7171
showRecordId?: boolean;
72-
73-
/** @deprecated Use `awaitData` instead */
74-
awaitdata?: boolean;
75-
/** @deprecated Use `projection` instead */
76-
fields?: Document;
77-
/** @deprecated Limit the number of items to scan. */
78-
maxScan?: number;
79-
/** @deprecated An internal command for replaying a replica set’s oplog. */
80-
oplogReplay?: boolean;
81-
/** @deprecated Snapshot query. */
82-
snapshot?: boolean;
83-
/** @deprecated Show disk location of results. */
84-
showDiskLoc?: boolean;
85-
/** @deprecated Use `allowPartialResults` instead */
86-
partial?: boolean;
8772
}
8873

8974
const SUPPORTS_WRITE_CONCERN_AND_COLLATION = 5;
@@ -156,8 +141,8 @@ export class FindOperation extends CommandOperation<FindOptions, Document> {
156141
findCommand.sort = formattedOrderClause(options.sort);
157142
}
158143

159-
if (options.projection || options.fields) {
160-
let projection = options.projection || options.fields;
144+
if (options.projection) {
145+
let projection = options.projection;
161146
if (projection && !Buffer.isBuffer(projection) && Array.isArray(projection)) {
162147
projection = projection.length
163148
? projection.reduce((result, field) => {
@@ -222,10 +207,6 @@ export class FindOperation extends CommandOperation<FindOptions, Document> {
222207
findCommand.tailable = options.tailable;
223208
}
224209

225-
if (typeof options.oplogReplay === 'boolean') {
226-
findCommand.oplogReplay = options.oplogReplay;
227-
}
228-
229210
if (typeof options.timeout === 'boolean') {
230211
findCommand.noCursorTimeout = options.timeout;
231212
} else if (typeof options.noCursorTimeout === 'boolean') {
@@ -234,14 +215,10 @@ export class FindOperation extends CommandOperation<FindOptions, Document> {
234215

235216
if (typeof options.awaitData === 'boolean') {
236217
findCommand.awaitData = options.awaitData;
237-
} else if (typeof options.awaitdata === 'boolean') {
238-
findCommand.awaitData = options.awaitdata;
239218
}
240219

241220
if (typeof options.allowPartialResults === 'boolean') {
242221
findCommand.allowPartialResults = options.allowPartialResults;
243-
} else if (typeof options.partial === 'boolean') {
244-
findCommand.allowPartialResults = options.partial;
245222
}
246223

247224
if (options.collation) {
@@ -262,14 +239,6 @@ export class FindOperation extends CommandOperation<FindOptions, Document> {
262239
findCommand.allowDiskUse = options.allowDiskUse;
263240
}
264241

265-
if (typeof options.snapshot === 'boolean') {
266-
findCommand.snapshot = options.snapshot;
267-
}
268-
269-
if (typeof options.showDiskLoc === 'boolean') {
270-
findCommand.showDiskLoc = options.showDiskLoc;
271-
}
272-
273242
// TODO: use `MongoDBNamespace` through and through
274243
server.query(
275244
this.ns.toString(),

test/functional/core/tailable_cursor.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('Tailable cursor tests', function () {
77
return setupDatabase(this.configuration);
88
});
99

10-
it('should correctly perform awaitdata', {
10+
it('should correctly perform awaitData', {
1111
metadata: {
1212
requires: { topology: ['single', 'replicaset', 'sharded'], mongodb: '>=3.2' }
1313
},

test/functional/cursor.test.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ describe('Cursor', function () {
16771677
collection.insertOne({ x: 1, a: 2 }, configuration.writeConcernMax(), err => {
16781678
expect(err).to.not.exist;
16791679

1680-
collection.find({}, { fields: { x: 0 } }).toArray((err, items) => {
1680+
collection.find({}, { projection: { x: 0 } }).toArray((err, items) => {
16811681
expect(err).to.not.exist;
16821682
test.equal(1, items.length);
16831683
test.equal(2, items[0].a);
@@ -2184,8 +2184,8 @@ describe('Cursor', function () {
21842184
collection.insert({ a: 1 }, configuration.writeConcernMax(), err => {
21852185
expect(err).to.not.exist;
21862186

2187-
// Create cursor with awaitdata, and timeout after the period specified
2188-
const cursor = collection.find({}, { tailable: true, awaitdata: true });
2187+
// Create cursor with awaitData, and timeout after the period specified
2188+
const cursor = collection.find({}, { tailable: true, awaitData: true });
21892189
this.defer(() => cursor.close());
21902190

21912191
// Execute each
@@ -2196,7 +2196,7 @@ describe('Cursor', function () {
21962196

21972197
if (err != null) {
21982198
// Even though cursor is exhausted, should not close session
2199-
// unless cursor is manually closed, due to awaitdata / tailable
2199+
// unless cursor is manually closed, due to awaitData / tailable
22002200
done();
22012201
}
22022202
});
@@ -2228,8 +2228,8 @@ describe('Cursor', function () {
22282228
db.createCollection('should_await_data_no_docs', options, (err, collection) => {
22292229
expect(err).to.not.exist;
22302230

2231-
// Create cursor with awaitdata, and timeout after the period specified
2232-
const cursor = collection.find({}, { tailable: true, awaitdata: true });
2231+
// Create cursor with awaitData, and timeout after the period specified
2232+
const cursor = collection.find({}, { tailable: true, awaitData: true });
22332233
this.defer(() => cursor.close());
22342234

22352235
const rewind = cursor.rewind;
@@ -2273,7 +2273,7 @@ describe('Cursor', function () {
22732273

22742274
collection.insert({ a: 1 }, configuration.writeConcernMax(), err => {
22752275
expect(err).to.not.exist;
2276-
// Create cursor with awaitdata, and timeout after the period specified
2276+
// Create cursor with awaitData, and timeout after the period specified
22772277
const cursor = collection.find({}, {});
22782278
this.defer(() => cursor.close());
22792279

@@ -2282,7 +2282,7 @@ describe('Cursor', function () {
22822282
cursor.each(err => {
22832283
if (err != null) {
22842284
// Even though cursor is exhausted, should not close session
2285-
// unless cursor is manually closed, due to awaitdata / tailable
2285+
// unless cursor is manually closed, due to awaitData / tailable
22862286
done();
22872287
} else {
22882288
cursor.kill();
@@ -2309,7 +2309,7 @@ describe('Cursor', function () {
23092309
db.createCollection('should_not_await_data_when_false', options, function(err, collection) {
23102310
collection.insert({a:1}, configuration.writeConcernMax(), function(err, result) {
23112311
// should not timeout
2312-
collection.find({}, {tailable:true, awaitdata:false}).each(function(err, result) {
2312+
collection.find({}, {tailable:true, awaitData:false}).each(function(err, result) {
23132313
test.ok(err != null);
23142314
});
23152315
@@ -2345,8 +2345,8 @@ describe('Cursor', function () {
23452345
collection.insert({ a: 1 }, configuration.writeConcernMax(), err => {
23462346
expect(err).to.not.exist;
23472347

2348-
// Create cursor with awaitdata, and timeout after the period specified
2349-
var cursor = collection.find({}, { tailable: true, awaitdata: true });
2348+
// Create cursor with awaitData, and timeout after the period specified
2349+
var cursor = collection.find({}, { tailable: true, awaitData: true });
23502350
cursor.each(err => {
23512351
if (err != null) {
23522352
// kill cursor b/c cursor is tailable / awaitable
@@ -3528,7 +3528,7 @@ describe('Cursor', function () {
35283528
expect(err).to.not.exist;
35293529

35303530
var s = new Date();
3531-
// Create cursor with awaitdata, and timeout after the period specified
3531+
// Create cursor with awaitData, and timeout after the period specified
35323532
var cursor = collection
35333533
.find({})
35343534
.addCursorFlag('tailable', true)

test/functional/deprecate_warning.test.js

-119
This file was deleted.

test/functional/error.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('Errors', function () {
9090
const c = db.collection('test_error_object_should_include_message');
9191
c.insertOne({ a: 2, b: 5 }, { w: 1 }, err => {
9292
expect(err).to.not.exist;
93-
c.findOne({ a: 2 }, { fields: { a: 1, b: 0 } }, err => {
93+
c.findOne({ a: 2 }, { projection: { a: 1, b: 0 } }, err => {
9494
expect(PROJECTION_ERRORS).to.include(err.errmsg);
9595
done();
9696
});
@@ -103,7 +103,7 @@ describe('Errors', function () {
103103
test: function (done) {
104104
const db = client.db(this.configuration.db);
105105
const c = db.collection('test_error_object_should_include_message');
106-
c.findOne({}, { fields: { a: 1, b: 0 } }, err => {
106+
c.findOne({}, { projection: { a: 1, b: 0 } }, err => {
107107
expect(PROJECTION_ERRORS).to.include(err.errmsg);
108108
done();
109109
});

0 commit comments

Comments
 (0)