This commit is contained in:
2020-08-20 11:44:32 +02:00
parent 4715fc1814
commit 6aceefeb2f
2891 changed files with 11239 additions and 347539 deletions

View File

@@ -27,10 +27,6 @@ function Collection(name, conn, opts) {
opts.capped = {};
}
opts.bufferCommands = undefined === opts.bufferCommands
? true
: opts.bufferCommands;
if (typeof opts.capped === 'number') {
opts.capped = { size: opts.capped };
}
@@ -40,7 +36,7 @@ function Collection(name, conn, opts) {
this.collectionName = name;
this.conn = conn;
this.queue = [];
this.buffer = this.opts.bufferCommands;
this.buffer = true;
this.emitter = new EventEmitter();
if (STATES.connected === this.conn.readyState) {
@@ -93,7 +89,7 @@ Collection.prototype.onOpen = function() {
*/
Collection.prototype.onClose = function(force) {
if (this.opts.bufferCommands && !force) {
if (this._shouldBufferCommands() && !force) {
this.buffer = true;
}
};
@@ -262,6 +258,29 @@ Collection.prototype.watch = function() {
throw new Error('Collection#watch unimplemented by driver');
};
/*!
* ignore
*/
Collection.prototype._shouldBufferCommands = function _shouldBufferCommands() {
const conn = this.conn;
const opts = this.opts;
if (opts.bufferCommands != null) {
return opts.bufferCommands;
}
if (opts && opts.schemaUserProvidedOptions != null && opts.schemaUserProvidedOptions.bufferCommands != null) {
return opts.schemaUserProvidedOptions.bufferCommands;
}
if (conn.config.bufferCommands != null) {
return conn.config.bufferCommands;
}
if (conn.base != null && conn.base.get('bufferCommands') != null) {
return conn.base.get('bufferCommands');
}
return true;
};
/*!
* Module exports.
*/