Skip to content

Commit ac29513

Browse files
committed
NODE-572 Remove examples that use the second parameter to
1 parent 3c26ed3 commit ac29513

File tree

5 files changed

+49
-47
lines changed

5 files changed

+49
-47
lines changed

lib/aggregation_cursor.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ var inherits = require('util').inherits
3737
* , {a:2, b:2}, {a:3, b:3}
3838
* , {a:4, b:4}], {w:1}, function(err, result) {
3939
* test.equal(null, err);
40-
*
4140
* // Show that duplicate records got dropped
4241
* col.aggregation({}, {cursor: {}}).toArray(function(err, items) {
4342
* test.equal(null, err);

lib/db.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,17 +1411,17 @@ Db.prototype.authenticate = function(username, password, options, callback) {
14111411
// If we have a callback fallback
14121412
if(typeof callback == 'function') return authenticate(self, username, password, options, function(err, r) {
14131413
// Support failed auth method
1414-
if(err.message.indexOf('saslStart') != -1) err.code = 59;
1414+
if(err && err.message && err.message.indexOf('saslStart') != -1) err.code = 59;
14151415
// Reject error
1416-
if(err) return callback(err);
1416+
if(err) return callback(err, r);
14171417
callback(null, r);
14181418
});
14191419

14201420
// Return a promise
14211421
return new this.s.promiseLibrary(function(resolve, reject) {
14221422
authenticate(self, username, password, options, function(err, r) {
14231423
// Support failed auth method
1424-
if(err.message.indexOf('saslStart') != -1) err.code = 59;
1424+
if(err && err.message && err.message.indexOf('saslStart') != -1) err.code = 59;
14251425
// Reject error
14261426
if(err) return reject(err);
14271427
resolve(r);

test/functional/operation_example_tests.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ exports.shouldCreateComplexIndexOnTwoFields = {
538538
test.equal(4, items.length);
539539

540540
// Peform a query, with explain to show we hit the query
541-
collection.find({a:2}, {explain:true}).toArray(function(err, explanation) {
541+
collection.find({a:2}).explain(function(err, explanation) {
542542
test.equal(null, err);
543543
test.ok(explanation != null);
544544

@@ -586,7 +586,7 @@ exports.shouldCreateASimpleIndexOnASingleField = {
586586
test.equal("a_1", indexName);
587587

588588
// Peform a query, with explain to show we hit the query
589-
collection.find({a:2}, {explain:true}).toArray(function(err, explanation) {
589+
collection.find({a:2}).explain(function(err, explanation) {
590590
test.equal(null, err);
591591
test.ok(explanation != null);
592592

@@ -641,7 +641,7 @@ exports.createIndexExample3 = {
641641
test.equal(4, items.length);
642642

643643
// Peform a query, with explain to show we hit the query
644-
collection.find({a:2}, {explain:true}).toArray(function(err, explanation) {
644+
collection.find({a:2}).explain(function(err, explanation) {
645645
test.equal(null, err);
646646
test.ok(explanation != null);
647647

@@ -925,7 +925,7 @@ exports.shouldCreateComplexEnsureIndex = {
925925
test.equal(4, items.length);
926926

927927
// Peform a query, with explain to show we hit the query
928-
collection.find({a:2}, {explain:true}).toArray(function(err, explanation) {
928+
collection.find({a:2}).explain(function(err, explanation) {
929929
test.equal(null, err);
930930
test.ok(explanation != null);
931931

@@ -978,7 +978,7 @@ exports.ensureIndexExampleWithCompountIndex = {
978978
test.equal(4, items.length);
979979

980980
// Peform a query, with explain to show we hit the query
981-
collection.find({a:2}, {explain:true}).toArray(function(err, explanation) {
981+
collection.find({a:2}).explain(function(err, explanation) {
982982
test.equal(null, err);
983983
test.ok(explanation != null);
984984

@@ -1065,9 +1065,9 @@ exports.shouldPeformASimpleExplainQuery = {
10651065
test.equal(null, err);
10661066

10671067
// Peform a simple find and return all the documents
1068-
collection.find({}, {explain:true}).toArray(function(err, docs) {
1068+
collection.find({}).explain(function(err, explain) {
10691069
test.equal(null, err);
1070-
test.equal(1, docs.length);
1070+
test.ok(explain != null);
10711071

10721072
db.close();
10731073
test.done();
@@ -1107,14 +1107,15 @@ exports.shouldPeformASimpleLimitSkipQuery = {
11071107
test.equal(null, err);
11081108

11091109
// Peform a simple find and return all the documents
1110-
collection.find({}, {skip:1, limit:1, fields:{b:1}}).toArray(function(err, docs) {
1111-
test.equal(null, err);
1112-
test.equal(1, docs.length);
1113-
test.equal(null, docs[0].a);
1114-
test.equal(2, docs[0].b);
1110+
collection.find({})
1111+
.skip(1).limit(1).project({b:1}).toArray(function(err, docs) {
1112+
test.equal(null, err);
1113+
test.equal(1, docs.length);
1114+
test.equal(null, docs[0].a);
1115+
test.equal(2, docs[0].b);
11151116

1116-
db.close();
1117-
test.done();
1117+
db.close();
1118+
test.done();
11181119
});
11191120
});
11201121
});
@@ -3790,7 +3791,7 @@ exports.shouldCreateOnDbComplexIndexOnTwoFields = {
37903791
test.equal(4, items.length);
37913792

37923793
// Peform a query, with explain to show we hit the query
3793-
collection.find({a:2}, {explain:true}).toArray(function(err, explanation) {
3794+
collection.find({a:2}).explain(function(err, explanation) {
37943795
test.equal(null, err);
37953796
test.ok(explanation != null);
37963797

@@ -3844,7 +3845,7 @@ exports.shouldCreateComplexEnsureIndexDb = {
38443845
test.equal(4, items.length);
38453846

38463847
// Peform a query, with explain to show we hit the query
3847-
collection.find({a:2}, {explain:true}).toArray(function(err, explanation) {
3848+
collection.find({a:2}).explain(function(err, explanation) {
38483849
test.equal(null, err);
38493850
test.ok(explanation != null);
38503851

test/functional/operation_generators_example_tests.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ exports.shouldCreateComplexIndexOnTwoFieldsWithGenerators = {
225225
test.equal(4, items.length);
226226

227227
// Peform a query, with explain to show we hit the query
228-
var explanation = yield collection.find({a:2}, {explain:true}).toArray()
228+
var explanation = yield collection.find({a:2}).explain()
229229
test.ok(explanation != null);
230230

231231
db.close();
@@ -513,7 +513,7 @@ exports.shouldCreateComplexEnsureIndexWithGenerators = {
513513
test.equal(4, items.length);
514514

515515
// Peform a query, with explain to show we hit the query
516-
var explanation = yield collection.find({a:2}, {explain:true}).toArray();
516+
var explanation = yield collection.find({a:2}).explain();
517517
test.ok(explanation != null);
518518

519519
db.close();
@@ -563,7 +563,7 @@ exports.ensureIndexExampleWithCompountIndexWithGenerators = {
563563
test.equal(4, items.length);
564564

565565
// Peform a query, with explain to show we hit the query
566-
var explanation = yield collection.find({a:2}, {explain:true}).toArray();
566+
var explanation = yield collection.find({a:2}).explain();
567567
test.ok(explanation != null);
568568

569569
// Close db
@@ -652,8 +652,8 @@ exports.shouldPeformASimpleExplainQueryWithGenerators = {
652652
yield collection.insertMany([{a:1}, {a:2}, {a:3}], configuration.writeConcernMax());
653653

654654
// Peform a simple find and return all the documents
655-
var docs = yield collection.find({}, {explain:true}).toArray();
656-
test.equal(1, docs.length);
655+
var explain = yield collection.find({}).explain();
656+
test.ok(explain != null);
657657

658658
db.close();
659659
test.done();
@@ -695,14 +695,15 @@ exports.shouldPeformASimpleLimitSkipQueryWithGenerators = {
695695
yield collection.insertMany([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], configuration.writeConcernMax());
696696

697697
// Peform a simple find and return all the documents
698-
var docs = yield collection.find({}, {skip:1, limit:1, fields:{b:1}}).toArray();
699-
test.equal(1, docs.length);
700-
test.equal(null, docs[0].a);
701-
test.equal(2, docs[0].b);
698+
var docs = yield collection.find({})
699+
.skip(1).limit(1).project({b:1}).toArray();
700+
test.equal(1, docs.length);
701+
test.equal(null, docs[0].a);
702+
test.equal(2, docs[0].b);
702703

703-
// Close db
704-
db.close();
705-
test.done();
704+
// Close db
705+
db.close();
706+
test.done();
706707
});
707708
// END
708709
}
@@ -3191,7 +3192,7 @@ exports.shouldCreateOnDbComplexIndexOnTwoFieldsWithGenerators = {
31913192
test.equal(4, items.length);
31923193

31933194
// Peform a query, with explain to show we hit the query
3194-
var explanation = yield collection.find({a:2}, {explain:true}).toArray();
3195+
var explanation = yield collection.find({a:2}).explain();
31953196
test.ok(explanation != null);
31963197

31973198
db.close();
@@ -3243,7 +3244,7 @@ exports.shouldCreateComplexEnsureIndexDbWithGenerators = {
32433244
test.equal(4, items.length);
32443245

32453246
// Peform a query, with explain to show we hit the query
3246-
var explanation = yield collection.find({a:2}, {explain:true}).toArray();
3247+
var explanation = yield collection.find({a:2}).explain();
32473248
test.ok(explanation != null);
32483249

32493250
db.close();

test/functional/operation_promises_example_tests.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ exports.shouldCreateComplexIndexOnTwoFieldsWithPromises = {
210210
test.equal(4, items.length);
211211

212212
// Peform a query, with explain to show we hit the query
213-
collection.find({a:2}, {explain:true}).toArray().then(function(explanation) {
213+
collection.find({a:2}).explain().then(function(explanation) {
214214
test.ok(explanation != null);
215215

216216
db.close();
@@ -483,7 +483,7 @@ exports.shouldCreateComplexEnsureIndexWithPromises = {
483483
test.equal(4, items.length);
484484

485485
// Peform a query, with explain to show we hit the query
486-
collection.find({a:2}, {explain:true}).toArray().then(function(explanation) {
486+
collection.find({a:2}).explain().then(function(explanation) {
487487
test.ok(explanation != null);
488488

489489
db.close();
@@ -532,7 +532,7 @@ exports.ensureIndexExampleWithCompountIndexWithPromises = {
532532
test.equal(4, items.length);
533533

534534
// Peform a query, with explain to show we hit the query
535-
collection.find({a:2}, {explain:true}).toArray().then(function(explanation) {
535+
collection.find({a:2}).explain().then(function(explanation) {
536536
test.ok(explanation != null);
537537

538538
db.close();
@@ -615,8 +615,8 @@ exports.shouldPeformASimpleExplainQueryWithPromises = {
615615
collection.insertMany([{a:1}, {a:2}, {a:3}], configuration.writeConcernMax()).then(function(result) {
616616

617617
// Peform a simple find and return all the documents
618-
collection.find({}, {explain:true}).toArray().then(function(docs) {
619-
test.equal(1, docs.length);
618+
collection.find({}).explain().then(function(docs) {
619+
test.ok(docs != null);
620620

621621
db.close();
622622
test.done();
@@ -655,13 +655,14 @@ exports.shouldPeformASimpleLimitSkipQueryWithPromises = {
655655
collection.insertMany([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], configuration.writeConcernMax()).then(function(result) {
656656

657657
// Peform a simple find and return all the documents
658-
collection.find({}, {skip:1, limit:1, fields:{b:1}}).toArray().then(function(docs) {
659-
test.equal(1, docs.length);
660-
test.equal(null, docs[0].a);
661-
test.equal(2, docs[0].b);
658+
collection.find({})
659+
.skip(1).limit(1).project({b:1}).toArray().then(function(docs) {
660+
test.equal(1, docs.length);
661+
test.equal(null, docs[0].a);
662+
test.equal(2, docs[0].b);
662663

663-
db.close();
664-
test.done();
664+
db.close();
665+
test.done();
665666
});
666667
});
667668
});
@@ -3168,7 +3169,7 @@ exports.shouldCreateOnDbComplexIndexOnTwoFieldsWithPromises = {
31683169
test.equal(4, items.length);
31693170

31703171
// Peform a query, with explain to show we hit the query
3171-
collection.find({a:2}, {explain:true}).toArray().then(function(explanation) {
3172+
collection.find({a:2}).explain().then(function(explanation) {
31723173
test.ok(explanation != null);
31733174

31743175
db.close();
@@ -3219,7 +3220,7 @@ exports.shouldCreateComplexEnsureIndexDbWithPromises = {
32193220
test.equal(4, items.length);
32203221

32213222
// Peform a query, with explain to show we hit the query
3222-
collection.find({a:2}, {explain:true}).toArray().then(function(explanation) {
3223+
collection.find({a:2}).explain().then(function(explanation) {
32233224
test.ok(explanation != null);
32243225

32253226
db.close();

0 commit comments

Comments
 (0)