This commit is contained in:
Jonasz Bigda
2023-03-25 21:51:42 +01:00
parent 0db1d5117e
commit b332e9ceb0
1044 changed files with 37502 additions and 63938 deletions

47
node_modules/mongodb/lib/cursor.js generated vendored
View File

@@ -12,6 +12,8 @@ const Map = require('./core').BSON.Map;
const maybePromise = require('./utils').maybePromise;
const executeOperation = require('./operations/execute_operation');
const formattedOrderClause = require('./utils').formattedOrderClause;
const Explain = require('./explain').Explain;
const Aspect = require('./operations/operation').Aspect;
const each = require('./operations/cursor_ops').each;
const CountOperation = require('./operations/count');
@@ -81,7 +83,6 @@ const fields = ['numberOfRetries', 'tailableRetryInterval'];
* collection.find({}).filter({a:1}) // Set query on the cursor
* collection.find({}).comment('add a comment') // Add a comment to the query, allowing to correlate queries
* collection.find({}).addCursorFlag('tailable', true) // Set cursor as tailable
* collection.find({}).addCursorFlag('oplogReplay', true) // Set cursor as oplogReplay
* collection.find({}).addCursorFlag('noCursorTimeout', true) // Set cursor as noCursorTimeout
* collection.find({}).addCursorFlag('awaitData', true) // Set cursor as awaitData
* collection.find({}).addCursorFlag('partial', true) // Set cursor as partial
@@ -164,6 +165,10 @@ class Cursor extends CoreCursor {
return this.cmd.sort;
}
set session(clientSession) {
this.cursorState.session = clientSession;
}
_initializeCursor(callback) {
if (this.operation && this.operation.session != null) {
this.cursorState.session = this.operation.session;
@@ -741,7 +746,12 @@ class Cursor extends CoreCursor {
return false;
}
if (doc != null) {
iterator(doc);
try {
iterator(doc);
} catch (error) {
callback(error);
return false;
}
return true;
}
if (doc == null && callback) {
@@ -761,7 +771,12 @@ class Cursor extends CoreCursor {
fulfill(null);
return false;
} else {
iterator(doc);
try {
iterator(doc);
} catch (error) {
reject(error);
return false;
}
return true;
}
});
@@ -1000,25 +1015,25 @@ class Cursor extends CoreCursor {
/**
* Execute the explain for the cursor
*
* For backwards compatibility, a verbosity of true is interpreted as "allPlansExecution"
* and false as "queryPlanner". Prior to server version 3.6, aggregate()
* ignores the verbosity parameter and executes in "queryPlanner".
*
* @method
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [verbosity=true] - An optional mode in which to run the explain.
* @param {Cursor~resultCallback} [callback] The result callback.
* @return {Promise} returns Promise if no callback passed
*/
explain(callback) {
// NOTE: the next line includes a special case for operations which do not
// subclass `CommandOperationV2`. To be removed asap.
if (this.operation && this.operation.cmd == null) {
this.operation.options.explain = true;
this.operation.fullResponse = false;
return executeOperation(this.topology, this.operation, callback);
}
explain(verbosity, callback) {
if (typeof verbosity === 'function') (callback = verbosity), (verbosity = true);
if (verbosity === undefined) verbosity = true;
this.cmd.explain = true;
// Do we have a readConcern
if (this.cmd.readConcern) {
delete this.cmd['readConcern'];
if (!this.operation || !this.operation.hasAspect(Aspect.EXPLAINABLE)) {
throw new MongoError('This command cannot be explained');
}
this.operation.explain = new Explain(verbosity);
return maybePromise(this, callback, cb => {
CoreCursor.prototype._next.apply(this, [cb]);
});