Skip to content

Commit

Permalink
refactor!: remove deprecated find options
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Reggi committed Oct 15, 2020
1 parent 054838f commit 0e6375a
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 227 deletions.
41 changes: 0 additions & 41 deletions src/cursor/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,21 +329,6 @@ export class Cursor<
return this;
}

/**
* Set the cursor maxScan
*
* @deprecated Instead, use maxTimeMS option or the helper {@link Cursor.maxTimeMS}.
* @param maxScan - Constrains the query to only scan the specified number of documents when fulfilling the query
*/
maxScan(maxScan: number): this {
if (this.s.state === CursorState.CLOSED || this.s.state === CursorState.OPEN || this.isDead()) {
throw new MongoError('Cursor is closed');
}

this.cmd.maxScan = maxScan;
return this;
}

/**
* Set the cursor hint
*
Expand Down Expand Up @@ -416,27 +401,10 @@ export class Cursor<
return this;
}

/**
* Set the cursor snapshot
*
* @deprecated as of MongoDB 4.0
*
* @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.
*/
snapshot(value: boolean): this {
if (this.s.state === CursorState.CLOSED || this.s.state === CursorState.OPEN || this.isDead()) {
throw new MongoError('Cursor is closed');
}

this.cmd.snapshot = value;
return this;
}

/**
* Set a node.js specific cursor option
*
* @param field - The cursor option to set 'numberOfRetries' | 'tailableRetryInterval'.
*
* @param value - The field value.
*/
setCursorOption(field: typeof FIELDS[number], value: number): this {
Expand Down Expand Up @@ -977,12 +945,3 @@ export class Cursor<

// deprecated methods
deprecate(Cursor.prototype.each, 'Cursor.each is deprecated. Use Cursor.forEach instead.');
deprecate(
Cursor.prototype.maxScan,
'Cursor.maxScan is deprecated, and will be removed in a later version'
);

deprecate(
Cursor.prototype.snapshot,
'Cursor Snapshot is deprecated, and will be removed in a later version'
);
2 changes: 1 addition & 1 deletion src/gridfs-stream/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ function checkDone(stream: GridFSBucketWriteStream, callback?: Callback): boolea
}

function checkIndexes(stream: GridFSBucketWriteStream, callback: Callback): void {
stream.files.findOne({}, { fields: { _id: 1 } }, (error, doc) => {
stream.files.findOne({}, { projection: { _id: 1 } }, (error, doc) => {
if (error) {
return callback(error);
}
Expand Down
35 changes: 2 additions & 33 deletions src/operations/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,6 @@ export interface FindOptions extends QueryOptions, CommandOperationOptions {
allowPartialResults?: boolean;
/** Determines whether to return the record identifier for each document. If true, adds a field $recordId to the returned documents. */
showRecordId?: boolean;

/** @deprecated Use `awaitData` instead */
awaitdata?: boolean;
/** @deprecated Use `projection` instead */
fields?: Document;
/** @deprecated Limit the number of items to scan. */
maxScan?: number;
/** @deprecated An internal command for replaying a replica set’s oplog. */
oplogReplay?: boolean;
/** @deprecated Snapshot query. */
snapshot?: boolean;
/** @deprecated Show disk location of results. */
showDiskLoc?: boolean;
/** @deprecated Use `allowPartialResults` instead */
partial?: boolean;
}

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

if (options.projection || options.fields) {
let projection = options.projection || options.fields;
if (options.projection) {
let projection = options.projection;
if (projection && !Buffer.isBuffer(projection) && Array.isArray(projection)) {
projection = projection.length
? projection.reduce((result, field) => {
Expand Down Expand Up @@ -222,10 +207,6 @@ export class FindOperation extends CommandOperation<FindOptions, Document> {
findCommand.tailable = options.tailable;
}

if (typeof options.oplogReplay === 'boolean') {
findCommand.oplogReplay = options.oplogReplay;
}

if (typeof options.timeout === 'boolean') {
findCommand.noCursorTimeout = options.timeout;
} else if (typeof options.noCursorTimeout === 'boolean') {
Expand All @@ -234,14 +215,10 @@ export class FindOperation extends CommandOperation<FindOptions, Document> {

if (typeof options.awaitData === 'boolean') {
findCommand.awaitData = options.awaitData;
} else if (typeof options.awaitdata === 'boolean') {
findCommand.awaitData = options.awaitdata;
}

if (typeof options.allowPartialResults === 'boolean') {
findCommand.allowPartialResults = options.allowPartialResults;
} else if (typeof options.partial === 'boolean') {
findCommand.allowPartialResults = options.partial;
}

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

if (typeof options.snapshot === 'boolean') {
findCommand.snapshot = options.snapshot;
}

if (typeof options.showDiskLoc === 'boolean') {
findCommand.showDiskLoc = options.showDiskLoc;
}

// TODO: use `MongoDBNamespace` through and through
server.query(
this.ns.toString(),
Expand Down
2 changes: 1 addition & 1 deletion test/functional/core/tailable_cursor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Tailable cursor tests', function () {
return setupDatabase(this.configuration);
});

it('should correctly perform awaitdata', {
it('should correctly perform awaitData', {
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded'], mongodb: '>=3.2' }
},
Expand Down
24 changes: 12 additions & 12 deletions test/functional/cursor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,7 @@ describe('Cursor', function () {
collection.insertOne({ x: 1, a: 2 }, configuration.writeConcernMax(), err => {
expect(err).to.not.exist;

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

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

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

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

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

const rewind = cursor.rewind;
Expand Down Expand Up @@ -2273,7 +2273,7 @@ describe('Cursor', function () {

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

Expand All @@ -2282,7 +2282,7 @@ describe('Cursor', function () {
cursor.each(err => {
if (err != null) {
// Even though cursor is exhausted, should not close session
// unless cursor is manually closed, due to awaitdata / tailable
// unless cursor is manually closed, due to awaitData / tailable
done();
} else {
cursor.kill();
Expand All @@ -2309,7 +2309,7 @@ describe('Cursor', function () {
db.createCollection('should_not_await_data_when_false', options, function(err, collection) {
collection.insert({a:1}, configuration.writeConcernMax(), function(err, result) {
// should not timeout
collection.find({}, {tailable:true, awaitdata:false}).each(function(err, result) {
collection.find({}, {tailable:true, awaitData:false}).each(function(err, result) {
test.ok(err != null);
});
Expand Down Expand Up @@ -2345,8 +2345,8 @@ describe('Cursor', function () {
collection.insert({ a: 1 }, configuration.writeConcernMax(), err => {
expect(err).to.not.exist;

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

var s = new Date();
// Create cursor with awaitdata, and timeout after the period specified
// Create cursor with awaitData, and timeout after the period specified
var cursor = collection
.find({})
.addCursorFlag('tailable', true)
Expand Down
119 changes: 0 additions & 119 deletions test/functional/deprecate_warning.test.js

This file was deleted.

4 changes: 2 additions & 2 deletions test/functional/error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('Errors', function () {
const c = db.collection('test_error_object_should_include_message');
c.insertOne({ a: 2, b: 5 }, { w: 1 }, err => {
expect(err).to.not.exist;
c.findOne({ a: 2 }, { fields: { a: 1, b: 0 } }, err => {
c.findOne({ a: 2 }, { projection: { a: 1, b: 0 } }, err => {
expect(PROJECTION_ERRORS).to.include(err.errmsg);
done();
});
Expand All @@ -103,7 +103,7 @@ describe('Errors', function () {
test: function (done) {
const db = client.db(this.configuration.db);
const c = db.collection('test_error_object_should_include_message');
c.findOne({}, { fields: { a: 1, b: 0 } }, err => {
c.findOne({}, { projection: { a: 1, b: 0 } }, err => {
expect(PROJECTION_ERRORS).to.include(err.errmsg);
done();
});
Expand Down
Loading

0 comments on commit 0e6375a

Please sign in to comment.