Commit 95819b44 authored by Xavier Guimard's avatar Xavier Guimard

New upstream version 3.1.1

parent f1ad1aba
......@@ -29,6 +29,8 @@ out/
performance/
public/
.coverage_data/
.coveralls.yml
.eslintrc
docs/public
.nyc_output/
typings/
......
......@@ -23,7 +23,10 @@ jobs:
- stage: tests
node_js: 6
env: MONGODB_VERSION=3.4.x
env: MONGODB_VERSION=3.6.x
- stage: tests
node_js: 8
env: MONGODB_VERSION=3.4.x
env: MONGODB_VERSION=3.6.x
- stage: tests
node_js: 10
env: MONGODB_VERSION=3.6.x
......@@ -109,7 +109,7 @@ returned client. The default database is now used if no parameter is passed to
MongoClient.connect('mongodb://localhost:27017/test')
.then(client => client.db().collection('foo').insert({ a: 42 })
.then(() => ...)
.catc(err => ...);
.catch(err => ...);
```
## Other Changes
......
<a name="3.0.7"></a>
## [3.0.7](https://github.com/mongodb/node-mongodb-native/compare/v3.0.6...v3.0.7) (2018-04-17)
<a name="3.1.1"></a>
## [3.1.1](https://github.com/mongodb/node-mongodb-native/compare/v3.1.0...v3.1.1) (2018-07-05)
### Bug Fixes
* **client-ops:** return transform map to map rather than function ([b8b4bfa](https://github.com/mongodb/node-mongodb-native/commit/b8b4bfa))
* **collection:** correctly shallow clone passed in options ([2e6c4fa](https://github.com/mongodb/node-mongodb-native/commit/2e6c4fa))
* **collection:** countDocuments throws error when query doesn't match docs ([4e83556](https://github.com/mongodb/node-mongodb-native/commit/4e83556))
* **server:** remove unnecessary print statement ([20e11b3](https://github.com/mongodb/node-mongodb-native/commit/20e11b3))
<a name="3.1.0"></a>
# [3.1.0](https://github.com/mongodb/node-mongodb-native/compare/v3.0.6...v3.1.0) (2018-06-27)
### Bug Fixes
* **aggregte:** support user-provided `batchSize` ([ad10dee](https://github.com/mongodb/node-mongodb-native/commit/ad10dee))
* **bulk:** fixing retryable writes for mass-change ops ([0604036](https://github.com/mongodb/node-mongodb-native/commit/0604036))
* **bulk:** handle MongoWriteConcernErrors ([12ff392](https://github.com/mongodb/node-mongodb-native/commit/12ff392))
* **change_stream:** do not check isGetMore if error[mongoErrorContextSymbol] is undefined ([#1720](https://github.com/mongodb/node-mongodb-native/issues/1720)) ([844c2c8](https://github.com/mongodb/node-mongodb-native/commit/844c2c8))
* **change-stream:** fix change stream resuming with promises ([3063f00](https://github.com/mongodb/node-mongodb-native/commit/3063f00))
* **collection:** depend on `resolveReadPreference` for inheritance ([a649e35](https://github.com/mongodb/node-mongodb-native/commit/a649e35))
* **collection:** only send bypassDocumentValidation if true ([fdb828b](https://github.com/mongodb/node-mongodb-native/commit/fdb828b))
* **cursor:** cursor count with collation fix ([71879c3](https://github.com/mongodb/node-mongodb-native/commit/71879c3))
* **cursor:** cursor hasNext returns false when exhausted ([184b817](https://github.com/mongodb/node-mongodb-native/commit/184b817))
* **cursor:** cursor.count not respecting parent readPreference ([5a9fdf0](https://github.com/mongodb/node-mongodb-native/commit/5a9fdf0))
* **db:** don't send session down to createIndex command ([559c195](https://github.com/mongodb/node-mongodb-native/commit/559c195))
* **db:** throw readable error when creating `_id` with background: true ([b3ff3ed](https://github.com/mongodb/node-mongodb-native/commit/b3ff3ed))
* **findOneAndUpdate:** ensure that update documents contain atomic operators ([eb68074](https://github.com/mongodb/node-mongodb-native/commit/eb68074))
* **index:** export MongoNetworkError ([98ab29e](https://github.com/mongodb/node-mongodb-native/commit/98ab29e))
* **mongo-client:** pass arguments to ctor when new keyword is used ([d6c3417](https://github.com/mongodb/node-mongodb-native/commit/d6c3417))
* **mongos:** bubble up close events after the first one ([#1713](https://github.com/mongodb/node-mongodb-native/issues/1713)) ([3e91d77](https://github.com/mongodb/node-mongodb-native/commit/3e91d77)), closes [Automattic/mongoose#6249](https://github.com/Automattic/mongoose/issues/6249) [#1685](https://github.com/mongodb/node-mongodb-native/issues/1685)
* **parallelCollectionScan:** do not use implicit sessions on cursors ([2de470a](https://github.com/mongodb/node-mongodb-native/commit/2de470a))
* **retryWrites:** fixes more bulk ops to not use retryWrites ([69e5254](https://github.com/mongodb/node-mongodb-native/commit/69e5254))
* **topology-base:** sending `endSessions` is always skipped now ([a276cbe](https://github.com/mongodb/node-mongodb-native/commit/a276cbe))
* **txns:** omit writeConcern when in a transaction ([b88c938](https://github.com/mongodb/node-mongodb-native/commit/b88c938))
* **utils:** restructure inheritance rules for read preferences ([6a7dac1](https://github.com/mongodb/node-mongodb-native/commit/6a7dac1))
### Features
* **auth:** add support for SCRAM-SHA-256 ([f53195d](https://github.com/mongodb/node-mongodb-native/commit/f53195d))
* **changeStream:** Adding new 4.0 ChangeStream features ([2cb4894](https://github.com/mongodb/node-mongodb-native/commit/2cb4894))
* **changeStream:** allow resuming on getMore errors ([4ba5adc](https://github.com/mongodb/node-mongodb-native/commit/4ba5adc))
* **changeStream:** expanding changeStream resumable errors ([49fbafd](https://github.com/mongodb/node-mongodb-native/commit/49fbafd))
* **ChangeStream:** update default startAtOperationTime ([50a9f65](https://github.com/mongodb/node-mongodb-native/commit/50a9f65))
* **collection:** add colleciton level document mapping/unmapping ([d03335e](https://github.com/mongodb/node-mongodb-native/commit/d03335e))
* **collection:** Implement new count API ([a5240ae](https://github.com/mongodb/node-mongodb-native/commit/a5240ae))
* **Collection:** warn if callback is not function in find and findOne ([cddaba0](https://github.com/mongodb/node-mongodb-native/commit/cddaba0))
* **core:** bump core dependency to v3.1.0 ([855bfdb](https://github.com/mongodb/node-mongodb-native/commit/855bfdb))
* **cursor:** new cursor.transformStream method ([397fcd2](https://github.com/mongodb/node-mongodb-native/commit/397fcd2))
* **GridFS:** add option to disable md5 in file upload ([704a88e](https://github.com/mongodb/node-mongodb-native/commit/704a88e))
* **listCollections:** add support for nameOnly option ([d2d0367](https://github.com/mongodb/node-mongodb-native/commit/d2d0367))
* **parallelCollectionScan:** does not allow user to pass a session ([4da9e03](https://github.com/mongodb/node-mongodb-native/commit/4da9e03))
* **read-preference:** add transaction to inheritance rules ([18ca41d](https://github.com/mongodb/node-mongodb-native/commit/18ca41d))
* **read-preference:** unify means of read preference resolution ([#1738](https://github.com/mongodb/node-mongodb-native/issues/1738)) ([2995e11](https://github.com/mongodb/node-mongodb-native/commit/2995e11))
* **urlParser:** use core URL parser ([c1c5d8d](https://github.com/mongodb/node-mongodb-native/commit/c1c5d8d))
* **withSession:** add top level helper for session lifetime ([9976b86](https://github.com/mongodb/node-mongodb-native/commit/9976b86))
### Reverts
* **collection:** reverting collection-mapping features ([7298c76](https://github.com/mongodb/node-mongodb-native/commit/7298c76)), closes [#1698](https://github.com/mongodb/node-mongodb-native/issues/1698) [mongodb/js-bson#253](https://github.com/mongodb/js-bson/issues/253)
......
......@@ -15,7 +15,7 @@ The official [MongoDB](https://www.mongodb.com/) driver for Node.js. Provides a
| what | where |
|---------------|------------------------------------------------|
| documentation | http://mongodb.github.io/node-mongodb-native |
| api-doc | http://mongodb.github.io/node-mongodb-native/3.0/api |
| api-doc | http://mongodb.github.io/node-mongodb-native/3.1/api |
| source | https://github.com/mongodb/node-mongodb-native |
| mongodb | http://www.mongodb.org |
......
......@@ -51,7 +51,7 @@
"applicationName": "Node.js MongoDB Driver API",
"googleAnalytics": "UA-29229787-1",
"openGraph": {
"title": "",
"title": "MongoDB Driver API for Node.js",
"type": "website",
"image": "",
"site_name": "",
......
......@@ -13,7 +13,7 @@ title = "Frequently Asked Questions"
| Setting | Default Value MongoClient.connect | Description |
| :----------| :------------- | :------------- |
| connectTimeoutMS | 30000 | The connectTimeoutMS sets the number of milliseconds a socket stays inactive before closing during the connection phase of the driver. That is to say, when the application initiates a connection, when a replica set connects to new members, or when a replica set reconnects to members. A value of 10000 milliseconds would mean the driver would wait up to 10 seconds for a response from a MongoDB server.|
| socketTimeoutMS | 360000 | The socketTimeoutMS sets the number of milliseconds a socket stays inactive after the driver has successfully connected before closing. If the value is set to 360000 milliseconds, the socket closes if there is no activity during a 30 seconds window.|
| socketTimeoutMS | 360000 | The socketTimeoutMS sets the number of milliseconds a socket stays inactive after the driver has successfully connected before closing. If the value is set to 360000 milliseconds, the socket closes if there is no activity during a 6 minutes window.|
| maxTimeMS | N/A | The maxTimeMS setting specifies how long MongoDB should run an operation before cancelling it. If the maxTimeMS is set to 10000 milliseconds, any operation that runs over that limit returns a timeout error.|
#### Fail fast during connection
......
......@@ -149,7 +149,6 @@ The next example shows a complete `find` operation that results in multiple `get
},
"batchSize": 2,
"comment": "some comment",
"maxScan": 1000,
"maxTimeMS": 5000,
"noCursorTimeout": true
},
......
......@@ -12,7 +12,6 @@ title = "Authentication"
The Node.js driver supports all MongoDB [authentication mechanisms](http://docs.mongodb.org/manual/core/authentication/), including those only available in the MongoDB [Enterprise Edition](http://docs.mongodb.org/manual/administration/install-enterprise/).
## DEFAULT
{{% note %}}
......@@ -79,6 +78,10 @@ MongoClient.connect(url, function(err, client) {
## MONGODB-CR
{{% warning %}}
MONGODB-CR was deprecated starting in MongoDB 3.6, and is no longer supported as of MongoDB 4.0
{{% /warning %}}
To explicitly connect to MongoDB using [MONGODB-CR](https://docs.mongodb.org/manual/core/security-mongodb-cr/), specify `MONGODB-CR` as the mechanism in the [URI connection string](https://docs.mongodb.org/manual/reference/connection-string/).
Include the name and password and the [authentication database](https://docs.mongodb.org/manual/core/security-users/#user-authentication-database) (`authSource`) in the connection string.
......
......@@ -92,7 +92,7 @@ MongoDB also provides
support text search of string content. Text indexes can include any
field whose value is a string or an array of string elements.
This example specifies a text index key for the ``content`` field:
This example specifies a text index key for the ``comments`` field:
```js
{{% create-text-index %}}
......
......@@ -695,14 +695,12 @@ collection.find({}).addCursorFlag('awaitData', true) // Set cursor as
collection.find({}).addCursorFlag('exhaust', true) // Set cursor as exhaust
collection.find({}).addCursorFlag('partial', true) // Set cursor as partial
collection.find({}).addQueryModifier('$orderby', {a:1}) // Set $orderby {a:1}
collection.find({}).max(10) // Set the cursor maxScan
collection.find({}).maxScan(10) // Set the cursor maxScan
collection.find({}).max(10) // Set the cursor max
collection.find({}).maxTimeMS(1000) // Set the cursor maxTimeMS
collection.find({}).min(100) // Set the cursor min
collection.find({}).returnKey(10) // Set the cursor returnKey
collection.find({}).setReadPreference(ReadPreference.PRIMARY) // Set the cursor readPreference
collection.find({}).showRecordId(true) // Set the cursor showRecordId
collection.find({}).snapshot(true) // Set the cursor snapshot
collection.find({}).sort([['a', 1]]) // Sets the sort order of the cursor query
collection.find({}).hint('a_1') // Set the cursor hint
```
......@@ -710,7 +708,7 @@ collection.find({}).hint('a_1') // Set the cursor
All options are chainable, so you can combine settings in the following way:
```js
collection.find({}).maxTimeMS(1000).maxScan(100).skip(1).toArray(..)
collection.find({}).maxTimeMS(1000).skip(1).toArray(..)
```
More information can be found in the [Cursor API documentation](/node-mongodb-native/2.0/api/Cursor.html).
......
......@@ -163,7 +163,7 @@ bucket.openDownloadStreamByName('meistersinger.mp3').
on('error', function(error) {
assert.ifError(error);
}).
on('finish', function() {
on('end', function() {
console.log('done!');
process.exit(0);
});
......@@ -182,7 +182,7 @@ bucket.openDownloadStreamByName('meistersinger.mp3').
on('error', function(error) {
assert.ifError(error);
}).
on('finish', function() {
on('end', function() {
console.log('done!');
process.exit(0);
});
......
......@@ -9,6 +9,7 @@ const connect = require('./lib/mongo_client').connect;
// Expose error class
connect.MongoError = core.MongoError;
connect.MongoNetworkError = core.MongoNetworkError;
// Actual driver classes exported
connect.Admin = require('./lib/admin');
......
This diff is collapsed.
......@@ -9,7 +9,7 @@ class Instrumentation extends EventEmitter {
instrument(MongoClient, callback) {
// store a reference to the original functions
this.$MongoClient = MongoClient;
const $prototypeConnect = this.$prototypeConnect = MongoClient.prototype.connect; // eslint-disable-line
const $prototypeConnect = (this.$prototypeConnect = MongoClient.prototype.connect);
const instrumentation = this;
MongoClient.prototype.connect = function(callback) {
......
......@@ -51,6 +51,11 @@ var authenticate = function(client, username, password, options, callback) {
if (err) return handleCallback(callback, err, false);
_callback(null, true);
});
} else if (authMechanism === 'SCRAM-SHA-256') {
client.topology.auth('scram-sha-256', authdb, username, password, function(err) {
if (err) return handleCallback(callback, err, false);
_callback(null, true);
});
} else if (authMechanism === 'GSSAPI') {
if (process.platform === 'win32') {
client.topology.auth('sspi', authdb, username, password, options, function(err) {
......@@ -95,13 +100,14 @@ module.exports = function(self, username, password, options, callback) {
options.authMechanism !== 'MONGODB-CR' &&
options.authMechanism !== 'MONGODB-X509' &&
options.authMechanism !== 'SCRAM-SHA-1' &&
options.authMechanism !== 'SCRAM-SHA-256' &&
options.authMechanism !== 'PLAIN'
) {
return handleCallback(
callback,
MongoError.create({
message:
'only DEFAULT, GSSAPI, PLAIN, MONGODB-X509, SCRAM-SHA-1 or MONGODB-CR is supported by authMechanism',
'only DEFAULT, GSSAPI, PLAIN, MONGODB-X509, or SCRAM-SHA-1 is supported by authMechanism',
driver: true
})
);
......
'use strict';
var Long = require('mongodb-core').BSON.Long,
MongoError = require('mongodb-core').MongoError,
util = require('util');
const Long = require('mongodb-core').BSON.Long;
const MongoError = require('mongodb-core').MongoError;
const util = require('util');
const toError = require('../utils').toError;
const handleCallback = require('../utils').handleCallback;
// Error codes
var UNKNOWN_ERROR = 8;
......@@ -402,6 +404,20 @@ var cloneOptions = function(options) {
return clone;
};
function handleMongoWriteConcernError(batch, bulkResult, ordered, err, callback) {
mergeBatchResults(ordered, batch, bulkResult, null, err.result);
const wrappedWriteConcernError = new WriteConcernError({
errmsg: err.result.writeConcernError.errmsg,
code: err.result.writeConcernError.result
});
return handleCallback(
callback,
new BulkWriteError(toError(wrappedWriteConcernError), new BulkWriteResult(bulkResult)),
null
);
}
/**
* Creates a new BulkWriteError
*
......@@ -426,17 +442,21 @@ const BulkWriteError = function(error, result) {
util.inherits(BulkWriteError, MongoError);
// Exports symbols
exports.BulkWriteError = BulkWriteError;
exports.BulkWriteResult = BulkWriteResult;
exports.WriteError = WriteError;
exports.Batch = Batch;
exports.LegacyOp = LegacyOp;
exports.mergeBatchResults = mergeBatchResults;
exports.cloneOptions = cloneOptions;
exports.INVALID_BSON_ERROR = INVALID_BSON_ERROR;
exports.WRITE_CONCERN_ERROR = WRITE_CONCERN_ERROR;
exports.MULTIPLE_ERROR = MULTIPLE_ERROR;
exports.UNKNOWN_ERROR = UNKNOWN_ERROR;
exports.INSERT = INSERT;
exports.UPDATE = UPDATE;
exports.REMOVE = REMOVE;
module.exports = {
Batch,
BulkWriteError,
BulkWriteResult,
cloneOptions,
handleMongoWriteConcernError,
LegacyOp,
mergeBatchResults,
INVALID_BSON_ERROR: INVALID_BSON_ERROR,
MULTIPLE_ERROR: MULTIPLE_ERROR,
UNKNOWN_ERROR: UNKNOWN_ERROR,
WRITE_CONCERN_ERROR: WRITE_CONCERN_ERROR,
INSERT: INSERT,
UPDATE: UPDATE,
REMOVE: REMOVE,
WriteError,
WriteConcernError
};
......@@ -13,6 +13,8 @@ const mergeBatchResults = common.mergeBatchResults;
const executeOperation = utils.executeOperation;
const BulkWriteError = require('./common').BulkWriteError;
const applyWriteConcern = utils.applyWriteConcern;
const MongoWriteConcernError = require('mongodb-core').MongoWriteConcernError;
const handleMongoWriteConcernError = require('./common').handleMongoWriteConcernError;
var bson = new BSON([
BSON.Binary,
......@@ -300,14 +302,13 @@ function OrderedBulkOperation(topology, collection, options) {
promiseLibrary: promiseLibrary,
// Fundamental error
err: null,
// Bypass validation
bypassDocumentValidation:
typeof options.bypassDocumentValidation === 'boolean'
? options.bypassDocumentValidation
: false,
// check keys
checkKeys: typeof options.checkKeys === 'boolean' ? options.checkKeys : true
};
// bypass Validation
if (options.bypassDocumentValidation === true) {
this.s.bypassDocumentValidation = true;
}
}
OrderedBulkOperation.prototype.raw = function(op) {
......@@ -437,15 +438,19 @@ var executeCommands = function(self, options, callback) {
var resultHandler = function(err, result) {
// Error is a driver related error not a bulk op error, terminate
if ((err && err.driver) || (err && err.message)) {
if (((err && err.driver) || (err && err.message)) && !(err instanceof MongoWriteConcernError)) {
return handleCallback(callback, err);
}
// If we have and error
if (err) err.ok = 0;
if (err instanceof MongoWriteConcernError) {
return handleMongoWriteConcernError(batch, self.s.bulkResult, true, err, callback);
}
// Merge the results together
var mergeResult = mergeBatchResults(true, batch, self.s.bulkResult, err, result);
const writeResult = new BulkWriteResult(self.s.bulkResult);
const mergeResult = mergeBatchResults(true, batch, self.s.bulkResult, err, result);
if (mergeResult != null) {
return handleCallback(callback, null, writeResult);
}
......@@ -490,6 +495,10 @@ var executeCommands = function(self, options, callback) {
finalOptions.writeConcern = self.s.writeConcern;
}
if (finalOptions.bypassDocumentValidation !== true) {
delete finalOptions.bypassDocumentValidation;
}
// Set an operationIf if provided
if (self.operationId) {
resultHandler.operationId = self.operationId;
......@@ -515,6 +524,17 @@ var executeCommands = function(self, options, callback) {
finalOptions.checkKeys = false;
}
if (finalOptions.retryWrites) {
if (batch.batchType === common.UPDATE) {
finalOptions.retryWrites = finalOptions.retryWrites && !batch.operations.some(op => op.multi);
}
if (batch.batchType === common.REMOVE) {
finalOptions.retryWrites =
finalOptions.retryWrites && !batch.operations.some(op => op.limit === 0);
}
}
try {
if (batch.batchType === common.INSERT) {
self.s.topology.insert(
......@@ -557,9 +577,9 @@ var executeCommands = function(self, options, callback) {
* Execute the ordered bulk operation
*
* @method
* @param {object} [options=null] Optional settings.
* @param {(number|string)} [options.w=null] The write concern.
* @param {number} [options.wtimeout=null] The write concern timeout.
* @param {object} [options] Optional settings.
* @param {(number|string)} [options.w] The write concern.
* @param {number} [options.wtimeout] The write concern timeout.
* @param {boolean} [options.j=false] Specify a journal write concern.
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
* @param {OrderedBulkOperation~resultCallback} [callback] The result callback
......
......@@ -13,6 +13,8 @@ const mergeBatchResults = common.mergeBatchResults;
const executeOperation = utils.executeOperation;
const BulkWriteError = require('./common').BulkWriteError;
const applyWriteConcern = utils.applyWriteConcern;
const MongoWriteConcernError = require('mongodb-core').MongoWriteConcernError;
const handleMongoWriteConcernError = require('./common').handleMongoWriteConcernError;
var bson = new BSON([
BSON.Binary,
......@@ -309,14 +311,13 @@ var UnorderedBulkOperation = function(topology, collection, options) {
collection: collection,
// Promise Library
promiseLibrary: promiseLibrary,
// Bypass validation
bypassDocumentValidation:
typeof options.bypassDocumentValidation === 'boolean'
? options.bypassDocumentValidation
: false,
// check keys
checkKeys: typeof options.checkKeys === 'boolean' ? options.checkKeys : true
};
// bypass Validation
if (options.bypassDocumentValidation === true) {
this.s.bypassDocumentValidation = true;
}
};
/**
......@@ -440,14 +441,21 @@ var executeBatch = function(self, batch, options, callback) {
finalOptions.writeConcern = self.s.writeConcern;
}
if (finalOptions.bypassDocumentValidation !== true) {
delete finalOptions.bypassDocumentValidation;
}
var resultHandler = function(err, result) {
// Error is a driver related error not a bulk op error, terminate
if ((err && err.driver) || (err && err.message)) {
if (((err && err.driver) || (err && err.message)) && !(err instanceof MongoWriteConcernError)) {
return handleCallback(callback, err);
}
// If we have and error
if (err) err.ok = 0;
if (err instanceof MongoWriteConcernError) {
return handleMongoWriteConcernError(batch, self.s.bulkResult, false, err, callback);
}
handleCallback(callback, null, mergeBatchResults(false, batch, self.s.bulkResult, err, result));
};
......@@ -476,6 +484,17 @@ var executeBatch = function(self, batch, options, callback) {
finalOptions.checkKeys = false;
}
if (finalOptions.retryWrites) {
if (batch.batchType === common.UPDATE) {
finalOptions.retryWrites = finalOptions.retryWrites && !batch.operations.some(op => op.multi);
}
if (batch.batchType === common.REMOVE) {
finalOptions.retryWrites =
finalOptions.retryWrites && !batch.operations.some(op => op.limit === 0);
}
}
try {
if (batch.batchType === common.INSERT) {
self.s.topology.insert(
......@@ -569,9 +588,9 @@ var executeBatches = function(self, options, callback) {
* Execute the ordered bulk operation
*
* @method
* @param {object} [options=null] Optional settings.
* @param {(number|string)} [options.w=null] The write concern.
* @param {number} [options.wtimeout=null] The write concern timeout.
* @param {object} [options] Optional settings.
* @param {(number|string)} [options.w] The write concern.
* @param {number} [options.wtimeout] The write concern timeout.
* @param {boolean} [options.j=false] Specify a journal write concern.
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
* @param {UnorderedBulkOperation~resultCallback} [callback] The result callback
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
'use strict';
const MongoNetworkError = require('mongodb-core').MongoNetworkError;
const mongoErrorContextSymbol = require('mongodb-core').mongoErrorContextSymbol;
const GET_MORE_NON_RESUMABLE_CODES = new Set([
136, // CappedPositionLost
237, // CursorKilled
11601 // Interrupted
]);
// From spec@https://github.com/mongodb/specifications/blob/35e466ddf25059cb30e4113de71cdebd3754657f/source/change-streams.rst#resumable-error:
//
// An error is considered resumable if it meets any of the following criteria:
// - any error encountered which is not a server error (e.g. a timeout error or network error)
// - any server error response from a getMore command excluding those containing the following error codes
// - Interrupted: 11601
// - CappedPositionLost: 136
// - CursorKilled: 237
// - a server error response with an error message containing the substring "not master" or "node is recovering"
//
// An error on an aggregate command is not a resumable error. Only errors on a getMore command may be considered resumable errors.
function isGetMoreError(error) {
if (error[mongoErrorContextSymbol]) {
return error[mongoErrorContextSymbol].isGetMore;
}
}
function isResumableError(error) {
if (!isGetMoreError(error)) {
return false;
}
return !!(
error instanceof MongoNetworkError ||
!GET_MORE_NON_RESUMABLE_CODES.has(error.code) ||
error.message.match(/not master/) ||
error.message.match(/node is recovering/)
);
}
module.exports = { GET_MORE_NON_RESUMABLE_CODES, isResumableError };
......@@ -15,11 +15,11 @@ module.exports = GridFSBucketReadStream;
* @param {Collection} files Handle for files collection
* @param {Object} readPreference The read preference to use
* @param {Object} filter The query to use to find the file document
* @param {Object} [options=null] Optional settings.
* @param {Number} [options.sort=null] Optional sort for the file find query
* @param {Number} [options.skip=null] Optional skip for the file find query
* @param {Number} [options.start=null] Optional 0-based offset in bytes to start streaming from
* @param {Number} [options.end=null] Optional 0-based offset in bytes to stop streaming before
* @param {Object} [options] Optional settings.
* @param {Number} [options.sort] Optional sort for the file find query
* @param {Number} [options.skip] Optional skip for the file find query
* @param {Number} [options.start] Optional 0-based offset in bytes to start streaming from
* @param {Number} [options.end] Optional 0-based offset in bytes to stop streaming before
* @fires GridFSBucketReadStream#error
* @fires GridFSBucketReadStream#file
* @return {GridFSBucketReadStream} a GridFSBucketReadStream instance.
......
......@@ -19,11 +19,11 @@ module.exports = GridFSBucket;
* Constructor for a streaming GridFS interface
* @class
* @param {Db} db A db handle
* @param {object} [options=null] Optional settings.
* @param {object} [options] Optional settings.
* @param {string} [options.bucketName="fs"] The 'files' and 'chunks' collections will be prefixed with the bucket name followed by a dot.
* @param {number} [options.chunkSizeBytes=255 * 1024] Number of bytes stored in each chunk. Defaults to 255KB
* @param {object} [options.writeConcern=null] Optional write concern to be passed to write operations, for instance `{ w: 1 }`
* @param {object} [options.readPreference=null] Optional read preference to be passed to read operations
* @param {object} [options.writeConcern] Optional write concern to be passed to write operations, for instance `{ w: 1 }`
* @param {object} [options.readPreference] Optional read preference to be passed to read operations
* @fires GridFSBucketWriteStream#index
* @return {GridFSBucket}
*/
......@@ -74,11 +74,12 @@ util.inherits(GridFSBucket, Emitter);
* file's id.
* @method
* @param {string} filename The value of the 'filename' key in the files doc
* @param {object} [options=null] Optional settings.
* @param {number} [options.chunkSizeBytes=null] Optional overwrite this bucket's chunkSizeBytes for this file
* @param {object} [options.metadata=null] Optional object to store in the file document's `metadata` field
* @param {string} [options.contentType=null] Optional string to store in the file document's `contentType` field
* @param {array} [options.aliases=null] Optional array of strings to store in the file document's `aliases` field
* @param {object} [options] Optional settings.
* @param {number} [options.chunkSizeBytes] Optional overwrite this bucket's chunkSizeBytes for this file
* @param {object} [options.metadata] Optional object to store in the file document's `metadata` field
* @param {string} [options.contentType] Optional string to store in the file document's `contentType` field
* @param {array} [options.aliases] Optional array of strings to store in the file document's `aliases` field
* @param {boolean} [options.disableMD5=false] If true, disables adding an md5 field to file data
* @return {GridFSBucketWriteStream}
*/
......@@ -101,11 +102,12 @@ GridFSBucket.prototype.openUploadStream = function(filename, options) {
* @method
* @param {string|number|object} id A custom id used to identify the file
* @param {string} filename The value of the 'filename' key in the files doc
* @param {object} [options=null] Optional settings.
* @param {number} [options.chunkSizeBytes=null] Optional overwrite this bucket's chunkSizeBytes for this file
* @param {object} [options.metadata=null] Optional object to store in the file document's `metadata` field
* @param {string} [options.contentType=null] Optional string to store in the file document's `contentType` field
* @param {array} [options.aliases=null] Optional array of strings to store in the file document's `aliases` field
* @param {object} [options] Optional settings.
* @param {number} [options.chunkSizeBytes] Optional overwrite this bucket's chunkSizeBytes for this file
* @param {object} [options.metadata] Optional object to store in the file document's `metadata` field
* @param {string} [options.contentType] Optional string to store in the file document's `contentType` field
* @param {array} [options.aliases] Optional array of strings to store in the file document's `aliases` field
* @param {boolean} [options.disableMD5=false] If true, disables adding an md5 field to file data
* @return {GridFSBucketWriteStream}
*/
......@@ -130,9 +132,9 @@ GridFSBucket.prototype.openUploadStreamWithId = function(id, filename, options)
* data from GridFS.
* @method
* @param {ObjectId} id The id of the file doc
* @param {Object} [options=null] Optional settings.
* @param {Number} [options.start=null] Optional 0-based offset in bytes to start streaming from
* @param {Number} [options.end=null] Optional 0-based offset in bytes to stop streaming before
* @param {Object} [options] Optional settings.
* @param {Number} [options.start] Optional 0-based offset in bytes to start streaming from
* @param {Number} [options.end] Optional 0-based offset in bytes to stop streaming before
* @return {GridFSBucketReadStream}
*/
......@@ -195,13 +197,13 @@ function _delete(_this, id, callback) {
* Convenience wrapper around find on the files collection
* @method
* @param {Object} filter
* @param {Object} [options=null] Optional settings for cursor
* @param {number} [options.batchSize=null] Optional batch size for cursor
* @param {number} [options.limit=null] Optional limit for cursor
* @param {number} [options.maxTimeMS=null] Optional maxTimeMS for cursor
* @param {boolean} [options.noCursorTimeout=null] Optionally set cursor's `noCursorTimeout` flag
* @param {number} [options.skip=null] Optional skip for cursor
* @param {object} [options.sort=null] Optional sort for cursor
* @param {Object} [options] Optional settings for cursor
* @param {number} [options.batchSize] Optional batch size for cursor