Skip to content

Commit 64395fb

Browse files
committed
merged in 2.0 branch
2 parents 83b3e0e + af66afc commit 64395fb

14 files changed

+599
-466
lines changed

HISTORY.md

Lines changed: 454 additions & 444 deletions
Large diffs are not rendered by default.

lib/collection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Collection.prototype.find = function() {
175175
options = args[0];
176176
}
177177

178-
if(len === 2 && !Array.isArray(fields)) {
178+
if(len === 2 && fields !== undefined && !Array.isArray(fields)) {
179179
var fieldKeys = Object.keys(fields);
180180
var is_option = false;
181181

lib/db.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var debugFields = ['authSource', 'w', 'wtimeout', 'j', 'native_parser', 'forceSe
5757
* @param {boolean} [options.raw=false] Return document results as raw BSON buffers.
5858
* @param {boolean} [options.promoteLongs=true] Promotes Long values to number if they fit inside the 53 bits resolution.
5959
* @param {number} [options.bufferMaxEntries=-1] Sets a cap on how many operations the driver will buffer up before giving up on getting a working connection, default is -1 which is unlimited.
60-
* @param {number} [options.numberOfRetries=5] Number of retries off connection.
60+
* @param {number} [options.numberOfRetries=5] Number of times a tailable cursor will re-poll when it gets nothing back.
6161
* @param {number} [options.retryMiliSeconds=500] Number of milliseconds between retries.
6262
* @param {(ReadPreference|string)} [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
6363
* @param {object} [options.pkFactory=null] A primary key factory object for generation of custom _id keys.
@@ -758,7 +758,6 @@ define.classMethod('dropCollection', {callback: true, promise:true});
758758
*/
759759
Db.prototype.dropDatabase = function(callback) {
760760
var self = this;
761-
if(typeof options == 'function') callback = options, options = {};
762761
// Drop database command
763762
var cmd = {'dropDatabase':1};
764763

lib/mongo_client.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,19 @@ var connect = function(url, options, callback) {
247247
new Db(object.dbName, __server, {w:1, native_parser:false}).open(function(err, db) {
248248
// Update number of servers
249249
totalNumberOfServers = totalNumberOfServers - 1;
250+
250251
// If no error do the correct checks
251252
if(!err) {
252253
// Close the connection
253254
db.close();
254255
var isMasterDoc = db.serverConfig.isMasterDoc;
256+
255257
// Check what type of server we have
256258
if(isMasterDoc.setName) {
257259
totalNumberOfMongodServers++;
258260
setName = isMasterDoc.setName;
259261
}
262+
260263
if(isMasterDoc.msg && isMasterDoc.msg == "isdbgrid") totalNumberOfMongosServers++;
261264
} else {
262265
error = err;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mongodb",
3-
"version": "2.0.39",
3+
"version": "2.0.41",
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.2.8"
16+
"mongodb-core": "1.2.10"
1717
, "readable-stream": "1.0.31"
1818
, "es6-promise": "2.1.1"
1919
},

test/functional/authentication_tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ exports.shouldCorrectlyRetrieveReplSetGetStatusWithPromises = {
7171
* @ignore
7272
*/
7373
exports.shouldCorrectlyCallValidateCollectionUsingAuthenticatedMode = {
74-
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
74+
metadata: { requires: { topology: ['single', 'ssl', 'heap', 'wiredtiger'] } },
7575

7676
// The actual test we wish to run
7777
test: function(configure, test) {

test/functional/find_tests.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,3 +2256,48 @@ exports['Should correctly execute parallelCollectionScan with single cursor emit
22562256
});
22572257
}
22582258
}
2259+
2260+
exports['Should simulate closed cursor'] = {
2261+
// Add a tag that our runner can trigger on
2262+
// in this case we are setting that node needs to be higher than 0.10.X to run
2263+
metadata: { requires: { mongodb: ">2.5.5", topology: ["single", "replicaset"] } },
2264+
2265+
// The actual test we wish to run
2266+
test: function(configuration, test) {
2267+
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1, auto_reconnect:false});
2268+
// Establish connection to db
2269+
db.open(function(err, db) {
2270+
var docs = [];
2271+
2272+
// Insert some documents
2273+
for(var i = 0; i < 1000; i++) {
2274+
docs.push({a:i});
2275+
}
2276+
2277+
// Get the collection
2278+
var collection = db.collection('parallelCollectionScan_4');
2279+
// Insert 1000 documents in a batch
2280+
collection.insert(docs, function(err, result) {
2281+
var results = [];
2282+
var numCursors = 1;
2283+
2284+
// Get the cursor
2285+
var cursor = collection.find({}).batchSize(2);
2286+
// Get next document
2287+
cursor.next(function(err, doc) {
2288+
test.equal(null, err);
2289+
test.ok(doc != null);
2290+
2291+
// Mess with state forcing a call to isDead on the cursor
2292+
cursor.s.state = 2;
2293+
2294+
cursor.next(function(err, doc) {
2295+
test.ok(err != null);
2296+
db.close();
2297+
test.done();
2298+
})
2299+
});
2300+
});
2301+
});
2302+
}
2303+
}

test/functional/gridfs_tests.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,20 +246,37 @@ exports.shouldCorrectlyHandleMultipleChunkGridStore = {
246246
var fs_client = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1});
247247

248248
fs_client.open(function(err, fs_client) {
249+
test.equal(null, err);
250+
249251
fs_client.dropDatabase(function(err, done) {
252+
test.equal(null, err);
253+
250254
var gridStore = new GridStore(fs_client, "test_gs_multi_chunk", "w");
251255
gridStore.open(function(err, gridStore) {
256+
test.equal(null, err);
257+
252258
gridStore.chunkSize = 512;
253259
var file1 = ''; var file2 = ''; var file3 = '';
254260
for(var i = 0; i < gridStore.chunkSize; i++) { file1 = file1 + 'x'; }
255261
for(var i = 0; i < gridStore.chunkSize; i++) { file2 = file2 + 'y'; }
256262
for(var i = 0; i < gridStore.chunkSize; i++) { file3 = file3 + 'z'; }
257263

258264
gridStore.write(file1, function(err, gridStore) {
265+
console.dir(err)
266+
test.equal(null, err);
267+
259268
gridStore.write(file2, function(err, gridStore) {
269+
test.equal(null, err);
270+
260271
gridStore.write(file3, function(err, gridStore) {
272+
test.equal(null, err);
273+
261274
gridStore.close(function(err, result) {
275+
test.equal(null, err);
276+
262277
fs_client.collection('fs.chunks', function(err, collection) {
278+
test.equal(null, err);
279+
263280
collection.count(function(err, count) {
264281
test.equal(3, count);
265282

@@ -3042,3 +3059,47 @@ exports['should correctly seek on file where size of file is a multiple of the c
30423059
});
30433060
}
30443061
}
3062+
3063+
/**
3064+
* @ignore
3065+
*/
3066+
exports['should correctly write fake png to gridstore'] = {
3067+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
3068+
3069+
// The actual test we wish to run
3070+
test: function(configuration, test) {
3071+
var MongoClient = configuration.require.MongoClient
3072+
, GridStore = configuration.require.GridStore
3073+
, ObjectID = configuration.require.ObjectID
3074+
, fs = require('fs')
3075+
, assert = require('assert');
3076+
3077+
// Connection URL
3078+
var url = 'mongodb://localhost:27017/myproject';
3079+
var id = new ObjectID();
3080+
3081+
// Create a test buffer
3082+
var buffer = new Buffer(200033);
3083+
3084+
// Use connect method to connect to the Server
3085+
MongoClient.connect(configuration.url(), function(err, db) {
3086+
assert.equal(null, err);
3087+
3088+
var gridStore = new GridStore(db, new ObjectID(), 'w', { "content_type": "image/png", "chunk_size": 1024*4 });
3089+
gridStore.open(function(err, gridStore) {
3090+
test.equal(null, err);
3091+
3092+
gridStore.write(buffer, function(err, result) {
3093+
test.equal(null, err);
3094+
3095+
gridStore.close(function(err, result) {
3096+
test.equal(null, err);
3097+
3098+
db.close();
3099+
test.done();
3100+
});
3101+
});
3102+
});
3103+
});
3104+
}
3105+
}

test/functional/mongo_client_tests.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,26 @@ exports['Should fail due to wrong uri user:password@localhost'] = {
352352
}
353353
}
354354
}
355+
356+
/**
357+
* @ignore
358+
*/
359+
exports["correctly timeout MongoClient connect using custom connectTimeoutMS"] = {
360+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
361+
362+
// The actual test we wish to run
363+
test: function(configuration, test) {
364+
var MongoClient = configuration.require.MongoClient;
365+
366+
var start = new Date();
367+
368+
MongoClient.connect('mongodb://example.com/test?connectTimeoutMS=1000&maxPoolSize=1', function(err, db) {
369+
// db.close();
370+
371+
var end = new Date();
372+
console.dir(end.getTime() - start.getTime())
373+
374+
test.done();
375+
});
376+
}
377+
}

test/functional/operation_example_tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ exports.shouldCreateComplexIndexOnTwoFields = {
529529
test.equal(null, err);
530530

531531
// Create an index on the a field
532-
db.createIndex('createIndexExample1', {a:1, b:1}
532+
collection.createIndex({a:1, b:1}
533533
, {unique:true, background:true, w:1}, function(err, indexName) {
534534

535535
// Show that duplicate records got dropped

0 commit comments

Comments
 (0)