Skip to content

Commit c1594e3

Browse files
committed
Merged 2.0 branch back into 2.1-alpha
2 parents ebf798d + a24a67c commit c1594e3

File tree

10 files changed

+156
-48
lines changed

10 files changed

+156
-48
lines changed

HISTORY.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2.0.33 05-20-2015
2+
-----------------
3+
- Bumped mongodb-core to 1.1.32.
4+
5+
2.0.32 05-19-2015
6+
-----------------
7+
- NODE-463 db.close immediately executes its callback.
8+
- Don't only emit server close event once (Issue #1276, https://github.com/vkarpov15).
9+
- NODE-464 Updated mongodb-core to 1.1.31 that uses a single socket connection to arbiters and hidden servers as well as emitting all event correctly.
10+
111
2.0.31 05-08-2015
212
-----------------
313
- NODE-461 Tripping on error "no chunks found for file, possibly corrupt" when there is no error.
@@ -10,11 +20,11 @@
1020
-----------------
1121
- NODE-444 Possible memory leak, too many listeners added.
1222
- NODE-459 Auth failure using Node 0.8.28, MongoDB 3.0.2 & mongodb-node-native 1.4.35.
13-
- Bumped mongodb-core to 1.2.26.
23+
- Bumped mongodb-core to 1.1.26.
1424

1525
2.0.28 04-24-2015
1626
-----------------
17-
- Bumped mongodb-core to 1.2.25
27+
- Bumped mongodb-core to 1.1.25
1828
- Added Cursor.prototype.setCursorOption to allow for setting node specific cursor options for tailable cursors.
1929
- NODE-430 Cursor.count() opts argument masked by var opts = {}
2030
- NODE-406 Implemented Cursor.prototype.map function tapping into MongoClient cursor transforms.

lib/collection.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ var insertOne = function(self, doc, options, callback) {
374374
insertDocuments(self, [doc], options, function(err, r) {
375375
if(callback == null) return;
376376
if(err && callback) return callback(err);
377+
// Workaround for pre 2.6 servers
378+
if(r == null) return callback(null, {result: {ok:1}});
379+
// Add values to top level to ensure crud spec compatibility
377380
r.insertedCount = r.result.n;
378381
r.insertedId = doc._id;
379382
if(callback) callback(null, r);
@@ -414,6 +417,7 @@ var insertMany = function(self, docs, options, callback) {
414417
insertDocuments(self, docs, options, function(err, r) {
415418
if(callback == null) return;
416419
if(err && callback) return callback(err);
420+
if(r == null) return callback(null, {result: {ok:1}});
417421
r.insertedCount = r.result.n;
418422
var ids = [];
419423
for(var i = 0; i < docs.length; i++) {
@@ -644,6 +648,7 @@ var updateOne = function(self, filter, update, options, callback) {
644648
if(callback == null) return;
645649
if(r == null) return callback(null, null);
646650
if(err && callback) return callback(err);
651+
if(r == null) return callback(null, {result: {ok:1}});
647652
r.matchedCount = r.result.n;
648653
r.modifiedCount = r.result.nModified != null ? r.result.nModified : r.result.n;
649654
r.upsertedId = Array.isArray(r.result.upserted) && r.result.upserted.length > 0 ? r.result.upserted[0] : null;
@@ -689,6 +694,7 @@ var replaceOne = function(self, filter, update, options, callback) {
689694
updateDocuments(self, filter, update, options, function(err, r) {
690695
if(callback == null) return;
691696
if(err && callback) return callback(err);
697+
if(r == null) return callback(null, {result: {ok:1}});
692698
r.matchedCount = r.result.n;
693699
r.modifiedCount = r.result.nModified != null ? r.result.nModified : r.result.n;
694700
r.upsertedId = Array.isArray(r.result.upserted) && r.result.upserted.length > 0 ? r.result.upserted[0] : null;
@@ -735,6 +741,7 @@ var updateMany = function(self, filter, update, options, callback) {
735741
updateDocuments(self, filter, update, options, function(err, r) {
736742
if(callback == null) return;
737743
if(err && callback) return callback(err);
744+
if(r == null) return callback(null, {result: {ok:1}});
738745
r.matchedCount = r.result.n;
739746
r.modifiedCount = r.result.nModified != null ? r.result.nModified : r.result.n;
740747
r.upsertedId = Array.isArray(r.result.upserted) && r.result.upserted.length > 0 ? r.result.upserted[0] : null;
@@ -840,6 +847,7 @@ var deleteOne = function(self, filter, options, callback) {
840847
removeDocuments(self, filter, options, function(err, r) {
841848
if(callback == null) return;
842849
if(err && callback) return callback(err);
850+
if(r == null) return callback(null, {result: {ok:1}});
843851
r.deletedCount = r.result.n;
844852
if(callback) callback(null, r);
845853
});
@@ -881,6 +889,7 @@ var deleteMany = function(self, filter, options, callback) {
881889
if(callback == null) return;
882890
if(r == null) return callback(null, null);
883891
if(err && callback) return callback(err);
892+
if(r == null) return callback(null, {result: {ok:1}});
884893
r.deletedCount = r.result.n;
885894
if(callback) callback(null, r);
886895
});
@@ -1301,6 +1310,8 @@ Collection.prototype.dropIndex = function(indexName, options, callback) {
13011310
callback = args.pop();
13021311
if(typeof callback != 'function') args.push(callback);
13031312
options = args.length ? args.shift() || {} : {};
1313+
// Run only against primary
1314+
options.readPreference = ReadPreference.PRIMARY;
13041315

13051316
// Execute using callback
13061317
if(typeof callback == 'function') return dropIndex(self, indexName, options, callback);

lib/db.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ var Db = function(databaseName, topology, options) {
184184
// Add listeners
185185
topology.once('error', createListener(self, 'error', self));
186186
topology.once('timeout', createListener(self, 'timeout', self));
187-
topology.once('close', createListener(self, 'close', self));
187+
topology.on('close', createListener(self, 'close', self));
188188
topology.once('parseError', createListener(self, 'parseError', self));
189189
topology.once('open', createListener(self, 'open', self));
190190
topology.once('fullsetup', createListener(self, 'fullsetup', self));
@@ -334,7 +334,11 @@ Db.prototype.close = function(force, callback) {
334334

335335
// Close parent db if set
336336
if(this.s.parentDb) this.s.parentDb.close();
337-
if(typeof callback == 'function') handleCallback(callback, null);
337+
// Callback after next event loop tick
338+
if(typeof callback == 'function') return process.nextTick(function() {
339+
handleCallback(callback, null);
340+
})
341+
338342
// Return dummy promise
339343
return new this.s.promiseLibrary(function(resolve, reject) {
340344
resolve();
@@ -829,12 +833,6 @@ var createIndex = function(self, name, fieldOrSpec, options, callback) {
829833
throw new MongoError("Cannot use a writeConcern without a provided callback");
830834
}
831835

832-
// Shallow clone the options
833-
options = shallowClone(options);
834-
835-
// Always set read preference to primary
836-
options.readPreference = ReadPreference.PRIMARY;
837-
838836
// Attempt to run using createIndexes command
839837
createIndexUsingCreateIndexes(self, name, fieldOrSpec, options, function(err, result) {
840838
if(err == null) return handleCallback(callback, err, result);
@@ -882,6 +880,10 @@ Db.prototype.createIndex = function(name, fieldOrSpec, options, callback) {
882880
options = args.length ? args.shift() || {} : {};
883881
options = typeof callback === 'function' ? options : callback;
884882
options = options == null ? {} : options;
883+
// Shallow clone the options
884+
options = shallowClone(options);
885+
// Run only against primary
886+
options.readPreference = ReadPreference.PRIMARY;
885887

886888
// If we have a callback fallback
887889
if(typeof callback == 'function') return createIndex(self, name, fieldOrSpec, options, callback);

lib/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ Server.prototype.connect = function(db, _options, callback) {
260260
// Set up listeners
261261
self.s.server.once('timeout', errorHandler('timeout'));
262262
self.s.server.once('error', errorHandler('error'));
263-
self.s.server.once('close', errorHandler('close'));
263+
self.s.server.on('close', errorHandler('close'));
264264
// Only called on destroy
265265
self.s.server.once('destroy', destroyHandler);
266266

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mongodb",
3-
"version": "2.0.31",
3+
"version": "2.1.0-alpha",
44
"description": "MongoDB legacy driver emulation layer on top of mongodb-core",
55
"main": "index.js",
66
"repository": {
@@ -13,7 +13,7 @@
1313
"legacy"
1414
],
1515
"dependencies": {
16-
"mongodb-core": "1.1.28"
16+
"mongodb-core": "1.1.32"
1717
, "readable-stream": "1.0.31"
1818
, "es6-promise": "2.1.1"
1919
},
@@ -29,7 +29,7 @@
2929
, "mongodb-tools": "~1.0"
3030
},
3131
"author": "Christian Kvalheim",
32-
"license": "Apache 2.0",
32+
"license": "Apache-2.0",
3333
"bugs": {
3434
"url": "https://github.com/mongodb/node-mongodb-native/issues"
3535
},

test/functional/authentication_tests.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -270,21 +270,21 @@ exports['Unordered bulk operation should fail correctly when not authenticated']
270270
}
271271
}
272272

273-
/**********************************************************************************************
273+
// /**********************************************************************************************
274274

275-
ReplsetRep ReplsetRepl tReplsetRe etRepl Repl t plsetReplse eplsetReplse
276-
setReplsetR setReplsetRe setReplset plsetR plsetRepls tReplsetRepl etReplsetRep
277-
pls pls epls plse epls pls epl etRep etRe lset setR pls Rep et
278-
tReplsetRe tRe etReplsetRe et plset epl set
279-
lsetRepls lsetRe plsetRepls pl Repls etRepl epl
280-
ReplsetR Replset tReplsetR tR Repls plsetRe et
281-
setReplse setRepl lse lse etRe tReplse pls
282-
epl Rep e epl Rep tRep Re lset lse tRe
283-
etR setRep etRe tRe set set se epls Repl Repl epl lse
284-
eplse eplset eplsetR plse Replse tReplsetRep etReplsetR lsetRep setR etRepls
285-
etRep tRep etReplsetRep setRep lsetReplset plsetRepl ReplsetRepls plsetRe
275+
// ReplsetRep ReplsetRepl tReplsetRe etRepl Repl t plsetReplse eplsetReplse
276+
// setReplsetR setReplsetRe setReplset plsetR plsetRepls tReplsetRepl etReplsetRep
277+
// pls pls epls plse epls pls epl etRep etRe lset setR pls Rep et
278+
// tReplsetRe tRe etReplsetRe et plset epl set
279+
// lsetRepls lsetRe plsetRepls pl Repls etRepl epl
280+
// ReplsetR Replset tReplsetR tR Repls plsetRe et
281+
// setReplse setRepl lse lse etRe tReplse pls
282+
// epl Rep e epl Rep tRep Re lset lse tRe
283+
// etR setRep etRe tRe set set se epls Repl Repl epl lse
284+
// eplse eplset eplsetR plse Replse tReplsetRep etReplsetR lsetRep setR etRepls
285+
// etRep tRep etReplsetRep setRep lsetReplset plsetRepl ReplsetRepls plsetRe
286286

287-
**********************************************************************************************/
287+
// **********************************************************************************************/
288288

289289
var replSetManager;
290290

@@ -342,7 +342,7 @@ exports['Should correctly handle replicaset master stepdown and stepup without l
342342
// Connect
343343
new Db('replicaset_test_auth', replSet, {w:1}).open(function(err, db) {
344344
// Just set auths for the manager to handle it correctly
345-
replSetManager.setCredentials("mongocr", "admin", "root", "root");
345+
replSetManager.setCredentials("default", "admin", "root", "root");
346346
// Add a user
347347
db.admin().addUser("root", "root", {w:4, wtimeout: 25000}, function(err, result) {
348348
// test.equal(null, err);
@@ -408,7 +408,7 @@ exports.shouldCorrectlyAuthenticateUsingPrimary = {
408408
// test.equal(null, err);
409409

410410
// Just set auths for the manager to handle it correctly
411-
replSetManager.setCredentials("mongocr", "node-native-test", "me", "secret");
411+
replSetManager.setCredentials("default", "node-native-test", "me", "secret");
412412

413413
// Close the connection
414414
db.close();
@@ -473,7 +473,7 @@ exports.shouldCorrectlyAuthenticateWithTwoSeeds = {
473473

474474
db.addUser("me", "secret", {w:4, wtimeout: 25000}, function(err, result) {
475475
// Just set auths for the manager to handle it correctly
476-
replSetManager.setCredentials("mongocr", "node-native-test", "me", "secret");
476+
replSetManager.setCredentials("default", "node-native-test", "me", "secret");
477477

478478
// Close the connection
479479
db.close();
@@ -541,7 +541,7 @@ exports.shouldCorrectlyAuthenticateWithOnlySecondarySeed = {
541541
p_db.close();
542542

543543
// Just set auths for the manager to handle it correctly
544-
replSetManager.setCredentials("mongocr", "admin", "me", "secret");
544+
replSetManager.setCredentials("default", "admin", "me", "secret");
545545

546546
// connection string
547547
var config = f("mongodb://me:secret@localhost:%s/node-native-test?authSource=admin&readPreference=secondary&replicaSet=%s&maxPoolSize=1"
@@ -639,7 +639,7 @@ exports.shouldCorrectlyAuthenticateWithMultipleLoginsAndLogouts = {
639639
// test.ok(result != null);
640640

641641
// Just set auths for the manager to handle it correctly
642-
replSetManager.setCredentials("mongocr", "admin", "me", "secret");
642+
replSetManager.setCredentials("default", "admin", "me", "secret");
643643

644644
db.collection("stuff", function(err, collection) {
645645
collection.insert({a:2}, {w: 3}, authenticate1);
@@ -774,15 +774,15 @@ exports.shouldCorrectlyAuthenticateAndEnsureIndex = {
774774

775775
db_p.admin().addUser("me", "secret", {w:4}, function runWhatever(err, result) {
776776
// Just set auths for the manager to handle it correctly
777-
replSetManager.setCredentials("mongocr", "admin", "me", "secret");
777+
replSetManager.setCredentials("default", "admin", "me", "secret");
778778

779779
db_p.admin().authenticate("me", "secret", function(err, result) {
780780
test.equal(null, err);
781781

782782
db_p.addUser('test', 'test', {w:4, wtimeout:25000}, function(err, result) {
783783

784784
// Just set auths for the manager to handle it correctly
785-
replSetManager.setCredentials("mongocr", "admin", "test", "test");
785+
replSetManager.setCredentials("default", "admin", "test", "test");
786786

787787
db_p.authenticate('test', 'test', function(err, replies) {
788788

@@ -847,15 +847,15 @@ exports.shouldCorrectlyAuthenticateAndUseReadPreference = {
847847

848848
db_p.admin().addUser("me", "secret", {w:4, wtimeout:25000}, function runWhatever(err, result) {
849849
// Just set auths for the manager to handle it correctly
850-
replSetManager.setCredentials("mongocr", "admin", "me", "secret");
850+
replSetManager.setCredentials("default", "admin", "me", "secret");
851851

852852
db_p.admin().authenticate("me", "secret", function(err, result) {
853853
test.equal(null, err);
854854

855855
db_p.addUser('test', 'test', {w:4, wtimeout:25000}, function(err, result) {
856856

857857
// Just set auths for the manager to handle it correctly
858-
replSetManager.setCredentials("mongocr", "admin", "test", "test");
858+
replSetManager.setCredentials("default", "admin", "test", "test");
859859

860860
db_p.authenticate('test', 'test', function(err, replies) {
861861
test.equal(null, err);
@@ -910,7 +910,7 @@ exports.shouldCorrectlyBringReplicasetStepDownPrimaryAndStillReadFromSecondary =
910910
test.ok(db_p != null);
911911
db_p.admin().addUser("me", "secret", {w:4, wtimeout:25000}, function runWhatever(err, result) {
912912
// Just set auths for the manager to handle it correctly
913-
replSetManager.setCredentials("mongocr", "admin", "me", "secret");
913+
replSetManager.setCredentials("default", "admin", "me", "secret");
914914

915915
db_p.admin().authenticate("me", "secret", function(err, result) {
916916
test.equal(null, err);
@@ -922,7 +922,7 @@ exports.shouldCorrectlyBringReplicasetStepDownPrimaryAndStillReadFromSecondary =
922922
test.equal(null, err);
923923
test.ok(result != null);
924924

925-
db.serverConfig.on('joined', function(t) {
925+
db.serverConfig.on('joined', function(t, s) {
926926
if(t == 'primary') {
927927
var counter = 1000;
928928
var errors = 0;
@@ -948,7 +948,7 @@ exports.shouldCorrectlyBringReplicasetStepDownPrimaryAndStillReadFromSecondary =
948948
}
949949
}
950950
});
951-
db.serverConfig.on('left', function(t) {
951+
db.serverConfig.on('left', function(t, s) {
952952
});
953953
// Step down the primary
954954
replSetManager.stepDown({force:true}, function(err, result) {
@@ -996,7 +996,7 @@ exports.shouldCorrectlyAuthWithSecondaryAfterKillPrimary = {
996996
test.equal(null, err);
997997

998998
// Just set auths for the manager to handle it correctly
999-
replSetManager.setCredentials("mongocr", "test", "me", "secret");
999+
replSetManager.setCredentials("default", "test", "me", "secret");
10001000

10011001
db_p.collection('test').insert({a:1}, {w:1}, function(err, result) {
10021002
test.equal(null, err);
@@ -1073,7 +1073,7 @@ exports.shouldCorrectlyAuthAgainstReplicaSetAdminDbUsingMongoClient = {
10731073

10741074
db_p.admin().addUser("me", "secret", {w:4, wtimeout:25000}, function runWhatever(err, result) {
10751075
// Just set auths for the manager to handle it correctly
1076-
replSetManager.setCredentials("mongocr", "admin", "me", "secret");
1076+
replSetManager.setCredentials("default", "admin", "me", "secret");
10771077

10781078
db_p.close();
10791079

@@ -1142,7 +1142,7 @@ exports.shouldCorrectlyAuthAgainstNormalDbUsingMongoClient = {
11421142

11431143
db_p.addUser("me", "secret", {w:4, wtimeout: 25000}, function runWhatever(err, result) {
11441144
// Just set auths for the manager to handle it correctly
1145-
replSetManager.setCredentials("mongocr", "admin", "me", "secret");
1145+
replSetManager.setCredentials("default", "admin", "me", "secret");
11461146

11471147
db_p.close();
11481148

@@ -1275,7 +1275,7 @@ exports['should correctly connect and authenticate against admin database using
12751275

12761276
db.addUser("me", "secret", {w:'majority'}, function(err, result) {
12771277
// Just set auths for the manager to handle it correctly
1278-
shardedManager.setCredentials("mongocr", "node-native-test", "me", "secret");
1278+
shardedManager.setCredentials("default", "node-native-test", "me", "secret");
12791279

12801280
// Close the connection
12811281
db.close();
@@ -1340,7 +1340,7 @@ exports['Should correctly handle replicaset master stepdown and stepup without l
13401340
db.addUser("me", "secret", {w:'majority'}, function(err, result) {
13411341

13421342
// Just set auths for the manager to handle it correctly
1343-
shardedManager.setCredentials("mongocr", "admin", "me", "secret");
1343+
shardedManager.setCredentials("default", "admin", "me", "secret");
13441344

13451345
// Close the connection
13461346
db.close();

0 commit comments

Comments
 (0)