Skip to content

Commit 39d9d2d

Browse files
committed
Merge branch 'master' into NODE-1561/master/unify-ignoreUndefined
2 parents 6a20101 + a54be7a commit 39d9d2d

File tree

10 files changed

+49
-136
lines changed

10 files changed

+49
-136
lines changed

src/cursor/cursor.ts

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { emitDeprecatedOptionWarning } from '../utils';
22
import { ReadPreference, ReadPreferenceLike } from '../read_preference';
3-
import { Transform, PassThrough, Readable } from 'stream';
3+
import { Readable } from 'stream';
44
import { deprecate } from 'util';
55
import { MongoError, AnyError } from '../error';
66
import {
@@ -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 {
@@ -918,32 +886,9 @@ export class Cursor<
918886

919887
/** Return a modified Readable stream including a possible transform method. */
920888
stream(options?: CursorStreamOptions): CursorStream {
921-
// TODO: replace this method with transformStream in next major release
922889
return new CursorStream(this, options);
923890
}
924891

925-
/**
926-
* Return a modified Readable stream that applies a given transform function, if supplied. If none supplied,
927-
* returns a stream of unmodified docs.
928-
*/
929-
transformStream(options?: CursorStreamOptions): Transform {
930-
const streamOptions: typeof options = options || {};
931-
if (typeof streamOptions.transform === 'function') {
932-
const stream = new Transform({
933-
objectMode: true,
934-
transform(chunk, encoding, callback) {
935-
if (streamOptions.transform) {
936-
this.push(streamOptions.transform(chunk));
937-
}
938-
callback();
939-
}
940-
});
941-
return this.stream().pipe(stream);
942-
}
943-
944-
return this.stream(options).pipe(new PassThrough({ objectMode: true }));
945-
}
946-
947892
/**
948893
* Execute the explain for the cursor
949894
*
@@ -977,12 +922,3 @@ export class Cursor<
977922

978923
// deprecated methods
979924
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 33 deletions
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;
@@ -147,8 +132,8 @@ export class FindOperation extends CommandOperation<FindOptions, Document> {
147132
findCommand.sort = formattedOrderClause(options.sort);
148133
}
149134

150-
if (options.projection || options.fields) {
151-
let projection = options.projection || options.fields;
135+
if (options.projection) {
136+
let projection = options.projection;
152137
if (projection && !Buffer.isBuffer(projection) && Array.isArray(projection)) {
153138
projection = projection.length
154139
? projection.reduce((result, field) => {
@@ -213,10 +198,6 @@ export class FindOperation extends CommandOperation<FindOptions, Document> {
213198
findCommand.tailable = options.tailable;
214199
}
215200

216-
if (typeof options.oplogReplay === 'boolean') {
217-
findCommand.oplogReplay = options.oplogReplay;
218-
}
219-
220201
if (typeof options.timeout === 'boolean') {
221202
findCommand.noCursorTimeout = options.timeout;
222203
} else if (typeof options.noCursorTimeout === 'boolean') {
@@ -225,14 +206,10 @@ export class FindOperation extends CommandOperation<FindOptions, Document> {
225206

226207
if (typeof options.awaitData === 'boolean') {
227208
findCommand.awaitData = options.awaitData;
228-
} else if (typeof options.awaitdata === 'boolean') {
229-
findCommand.awaitData = options.awaitdata;
230209
}
231210

232211
if (typeof options.allowPartialResults === 'boolean') {
233212
findCommand.allowPartialResults = options.allowPartialResults;
234-
} else if (typeof options.partial === 'boolean') {
235-
findCommand.allowPartialResults = options.partial;
236213
}
237214

238215
if (options.collation) {
@@ -253,14 +230,6 @@ export class FindOperation extends CommandOperation<FindOptions, Document> {
253230
findCommand.allowDiskUse = options.allowDiskUse;
254231
}
255232

256-
if (typeof options.snapshot === 'boolean') {
257-
findCommand.snapshot = options.snapshot;
258-
}
259-
260-
if (typeof options.showDiskLoc === 'boolean') {
261-
findCommand.showDiskLoc = options.showDiskLoc;
262-
}
263-
264233
// TODO: use `MongoDBNamespace` through and through
265234
server.query(
266235
this.ns.toString(),

test/functional/core/tailable_cursor.test.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 16 additions & 16 deletions
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)
@@ -4121,7 +4121,7 @@ describe('Cursor', function () {
41214121
.then(() => collection.insertMany(docs))
41224122
.then(() => {
41234123
cursor = collection.find();
4124-
return cursor.transformStream(transformParam);
4124+
return cursor.stream(transformParam);
41254125
})
41264126
.then(stream => {
41274127
stream.on('data', function (doc) {
@@ -4141,7 +4141,7 @@ describe('Cursor', function () {
41414141
});
41424142
};
41434143

4144-
it('transformStream should apply the supplied transformation function to each document in the stream', function (done) {
4144+
it('stream should apply the supplied transformation function to each document in the stream', function (done) {
41454145
const configuration = this.configuration;
41464146
const client = configuration.newClient({ w: 1 }, { poolSize: 1, auto_reconnect: false });
41474147
const expectedDocs = [
@@ -4152,15 +4152,15 @@ describe('Cursor', function () {
41524152
const config = {
41534153
client: client,
41544154
configuration: configuration,
4155-
collectionName: 'transformStream-test-transform',
4155+
collectionName: 'stream-test-transform',
41564156
transformFunc: doc => ({ _id: doc._id, b: doc.a.b, c: doc.a.c }),
41574157
expectedSet: new Set(expectedDocs)
41584158
};
41594159

41604160
testTransformStream(config, done);
41614161
});
41624162

4163-
it('transformStream should return a stream of unmodified docs if no transform function applied', function (done) {
4163+
it('stream should return a stream of unmodified docs if no transform function applied', function (done) {
41644164
const configuration = this.configuration;
41654165
const client = configuration.newClient({ w: 1 }, { poolSize: 1, auto_reconnect: false });
41664166
const expectedDocs = [

test/functional/error.test.js

Lines changed: 2 additions & 2 deletions
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)